<> be careful : This method is only applicable to MySQL and SQLServer database

<> Using properties useGeneratedKeys and keyProperty

*
useGeneratedKeys(true/false): Set whether to use JDBC Of getGenereatedKeys Method to get the primary key and assign it to keyProperty Set the domain model properties
* keyProperty : fill in java The field name of the object
<> Using examples

mapper
<insert id="addUser" parameterType="xxx.xxx.model.xx" useGeneratedKeys="true"
keyProperty="id"> insert into user(username, name, password) values
(#{item.username}, #{item.name}, #{item.password})</insert>
service
public void addUser(User user) { systemMapper.addUser(user); user.getId(); }
<>user.getId() Cannot get the latest primary key id

inspect dao Is the layer interface used @Param annotation
for example :
void addUser(@Param("item") User user);
So change it mapper.xml
<insert id="addUser" parameterType="xxx.xx.xx" useGeneratedKeys="true"
keyProperty="item.id"> insert into user(username, name, password) values
(#{item.username}, #{item.name}, #{item.password})</insert>

Technology
©2020 ioDraw All rights reserved
Sharing a script of hacker empire code rain , Simple and fun !-bash The Trojan horse , Have you ever met one ?k8s delete pod Zhejiang University data structure midterm examination questions Detailed explanation PHP Medium die,exit,returnlayui.table Examples of dynamically getting header and list data Interview questions : Handwritten list ( Include reverse linked list ) After the outbreak Which programming has a bright future PTA Quick sort Ctrip 2019 School recruitment LRU Cache