mybatis insertUseGeneratedKeys 返回主鍵為null


package tk.mybatis.mapper.common.special;

import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Options;
import tk.mybatis.mapper.provider.SpecialProvider;

public interface InsertUseGeneratedKeysMapper<T> {
    @Options(
        useGeneratedKeys = true,
        keyProperty = "id"
    )
    @InsertProvider(
        type = SpecialProvider.class,
        method = "dynamicSQL"
    )
    int insertUseGeneratedKeys(T var1);
}

1、使用  insertUseGeneratedKeys插入數據時,如果id字段不是AUTO_INCREMENT,則不會生成新的id

2、建表的時候主鍵名定義為id,否則不會返回主鍵


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM