Mybatis 总结

1、实体类Student

2、StudentMapper接口

    public void add(Student student);

3、StudentMapper.xml

  <mapper namespace="javastudy.StudentMapper">
    <insert id="add" parameterType="javastudy.Student" useGeneratedKeys="true" keyProperty="id">
        </mappers>

4、mybatis-config.xml

<mapper class="javastudy.StudentMapper"/>

5、测试类

错误总结

SQL外键字段取值要注意

Mybatis 总结

外键字段默认设置为NULL

Mybatis 总结

联级设置

Mybatis 总结

索引这里 一对一设置为唯一性,一对多设置为正常模式

Mybatis 总结

resultMap 属性注意

如果是单一对象,

用<association property="teacher" javaType="javastudy.Teacher">

如果是集合对象

用 <collection property="students" ofType="javastudy.Student">

两者都存在时association 必须在collection前面

Mybatis 总结