<> 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
【webpack】DLL plugin Principle analysis Combined with source code Transformer The most comprehensive , The deepest analysis filemanager-webpack-plugin Turn resources into zip Package and archive JavaScript study ( Function declaration and parameters ) mean value - Implementation and application of variance model _python_ Data analysis _9JAVA Snake games ( Source code + notes )SpringBoot integrate Redisson Implement delay queue python code , Easy to complete Snake games Thread.setDaemon Set up the Daemons Unity Code dynamic creation of preform in editor expansion function