pasite的gravatar头像
pasite 2019-04-14 23:05:09
Mybaits-@Options注解作用

Mybaits之@Options(useGeneratedKeys = true, keyProperty = “xxxx”)作用

useGeneratedKeys 设置为"true"表明要 MyBatis 获取由数据库自动生成的主键;

keyProperty="id"指定把获取到的主键值注入到 XXX(实体类) 的 id 属性。

如配置中开启了@Options(useGeneratedKeys = true")会报错


org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.executor.ExecutorException: Error getting generated key or setting result to parameter object. Cause: org.apache.ibatis.executor.ExecutorException: No setter found for the keyProperty ‘id’ in com.xx.xx.entity.xxxx.
在mapper层加上下面这句:

@Options(useGeneratedKeys = true, keyProperty = "majorId")


打赏
最近浏览
丶Movse  LV4 2022年6月2日
szy10998 2021年5月13日
暂无贡献等级
wxc144  LV2 2021年5月6日
1054959069 2020年12月9日
暂无贡献等级
adminuserchenli  LV2 2020年7月7日
dreamZ720  LV2 2020年6月29日
qqq123hjhjhjhj  LV1 2020年5月17日
forever25243  LV14 2020年5月14日
摘星手  LV5 2020年5月10日
test202020  LV1 2020年4月16日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友