Wondercease

浙ICP备2022017321号

mybatis插入返回主键

插入完对象之后,对象的主键参数会自动改变

解决方法:复制一个新的

自己手写的话

设置了 useGeneratedKeys=“true” ,且 keyProperty =xxx. id是Java对象的属性名

<insert id=”insertBatch” useGeneratedKeys=”true” keyProperty=”xxx.id”>

或使用plus

@Insert(value = “INSERT INTO t_XXXX” +

“XXX,XXX,XXX ” +

“VALUES (XXX,XXX,XXX)”)

@SelectKey(statement=”select LAST_INSERT_ID()”,keyProperty = “id”,before = false,resultType = Long.class)

Integer testInsert1(MessageMould messageMould);

发表评论

您的电子邮箱地址不会被公开。