Returns the auto-incrementing primary key when mybatis+mysql inserts

When using mybatis to perform the insert operation, you need to return the self-incrementing primary key. The answer is the same on the
Internet .
UseGeneratedKeys is set to true and
keyProperty is set to the primary key field of the entity class, as follows:
<insert id="add" parameterType="Entity" useGeneratedKeys="true" keyProperty="EntityId">
  insert into entity(...) values(...)
</insert>


I tried many times to no avail, and finally read the following document:

http://www.cnblogs.com/fsjohnhuang/p/4078659.html

I saw the most important chrysanthemum:
Note: The return value of the mapper interface is still the number of records successfully inserted, but the difference is that the primary key value has been assigned to the id of the domain model entity.


I hope that people who encounter the same problem can see my blog and take less detours.
Well, you can continue to write code happily o(^▽^)o

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327073767&siteId=291194637