mybatisPlus-extends BaseMapper

 * 如果自定义xxMapper继承了mybatis-plus的BaseMapper时,xxMapper中不能有insert()方法,因为BaseMapper中就有这个方法。
 * 1.如果对应的xxMapper.xml中有<insert id="insert"/>方法,则会执行该方法,相当于对BaseMapper中的insert()方法重写了;
 * 2.如果对应的xxMapper.xml中没有<insert id="insert"/>方法,则默认使用mybatis-plus的insert()方法。
 * 3.① service.insert(object) ,其中object不需要传id,mybatis-plus会自动生成;
 * 4.② 而继承了BaseMapper的xxMapper,在调用insert(object)时,其中object也不需要传id,mybatis-plus会自动生成;
 * */
    // 注意:1.BaseMapper<Object>的泛型不能写错,应该传入对应的对象;
    // 问题:Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException:
//                   Cannot add or update a child row: a foreign key constraint fails
    //       2.(因为id不会做非空判断)当插入的BUILD_ID、COMMUNITY_ID或者XIAOQU_ID字段的值在相关联的表里不存在的时候就会报错。
    public interface UserMapper extends BaseMapper<User> {

}
发布了241 篇原创文章 · 获赞 31 · 访问量 6万+

猜你喜欢

转载自blog.csdn.net/qq_40406929/article/details/103063314
今日推荐