When a record is inserted by default in MyBatis, the return value is the number of bars inserted in the record.
Now you want to get the primary key value of the record that is currently being inserted after inserting the record, add the following code to the Insert method:
<insert id= "Insert" parametertype= "Cn.com.pm.ppm.model.UserInfo" >
<selectkey resulttype= "Java.math.BigDecimal" order= "before" keyproperty= "id" >
Select T_user_info_seq.nextval from dual
</selectKey>
INSERT INTO T_user_info
<trim prefix= "(" suffix= ")" suffixoverrides= "," >
<IF test= "id! = NULL" >
Id
</if>
...
</insert>
After you add the following code
<selectkey resulttype= "Java.math.BigDecimal" order= "before" keyproperty= "id" >
Select T_user_info_seq.nextval from dual
</selectKey>
The return value obtained in the method is still the number of records inserted
But MyBatis set the primary key value to the inserted object
This article is from the "Dream Escape" blog, please be sure to keep this source http://pinmei.blog.51cto.com/7012784/1628029
MyBatis return primary key value after Oracle inserts an object