MyBatis 3.2.6 There are two ways to get the self-increment primary key when inserting
Take MySQL5.5 as an example:
Method 1:
<insert id= "Insert" parametertype= "person" usegeneratedkeys= "true" keyproperty= "id" >
Insert into person (NAME,PSWD) VALUES (#{name},#{pswd})
</insert>
Method 2:
<insert id= "Insert" parametertype= "person" >
<selectkey keyproperty= "id" resulttype= "long" >
select last_insert_id ()
insert into person (NAME,PSWD) values (#{name},#{pswd})
&NBSP;&NBSP;&NBSP;&NBSP;</INSERT>
The entity id attribute before insertion is 0;
The entity id attribute after insertion is the self-increment ID after saving;
The second method is more stable by taking the best of each.
************************************************
MyBatis 3.2.6 has been tested to give three reliable and usable formulations:
SELECT * from user where name like "%" #{name} "%"
SELECT * from user where name like '% ' | | #{name}| | ' %‘
SELECT * from user where name like '%${name}% '
After three comparisons, the first one belongs to precompiled SQL, the latter two are not, so it is recommended to use the second notation.
This article is from the "beautiful Dē‖java Question" blog, please be sure to keep this source http://teny32.blog.51cto.com/8027509/1729190
MyBatis Insert and query get self-increment primary key two method of selecting one