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