天天看點

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> {

}