Parametertype: parameter type, which can be omitted
MySQL supports auto-incrementing primary key, which is also used by mybatis statement.getGenreatedKeys ();
usegeneratedkeys = “true”; use self incrementing primary key to get the primary key value strategy
keyproperty; specify the corresponding primary key property, that is, after mybatis gets the primary key value, which property of JavaBean encapsulates the value
Oracle does not support self incrementing; Oracle uses sequence to simulate self incrementing;
the primary key of data inserted each time is the value obtained from the sequence; how to get this value
<insert id="addEmp" databaseId="oracle">
<!--
keyProperty:Which property of the javaBean the primary key value is encapsulated to find out
order="BEFORE":the current sql is run before inserting sql
AFTER: the current sql is run after the insert sql
resultType:the return value type of the checked out data
BEFORE running order.
first run selectKey query id sql; find out the id value encapsulated to the id property of the javaBean
In the run insert sql; you can take out the value corresponding to the id property
AFTER running order.
Run the insert sql first (take the new value from the sequence as id)
then run the selectKey query sql for id.
-->
<selectKey keyProperty="id" order="BEFORE" resultType="Integer">
<!-- Write sql statement to query primary key -->
<!-- BEFORE-->
select EMPLOYEES_SEQ.nextval from dual
<!-- AFTER:
select EMPLOYEES_SEQ.currval from dual -->
</selectKey>
<!-- The primary key at the time of insertion is obtained from the sequence -->
<!-- BEFORE:-->
insert into employees(EMPLOYEE_ID,LAST_NAME,EMAIL)
values(#{id},#{lastName},#{email<!-- ,jdbcType=NULL -->})
<!-- AFTER:
insert into employees(EMPLOYEE_ID,LAST_NAME,EMAIL)
values(employees_seq.nextval,#{lastName},#{email}) -->
</insert>
Read More:
- Mybatis single parameter pass in exception (How to Fix)
- Twitter’s distributed self increasing ID algorithm snowflake (Java version)
- keytool error: java.lang.Exception: Input not an X.509 certificate
- Springdatajpa @query with like @param
- Mybatis plus paging Plugin and Auto-fill
- Configuration of springboot + Druid connection pool
- Ecilpse: All Common Shortcut keys
- [Errno 14] PYCURL ERROR 7 – “couldn’t connect to host”
- Split log by date in log4j2 of spring boot
- Executing Maven command error: Java_HOME is not defined correctly executing maven
- [How to Fix]Spring 3.0 could not find acceptable representation
- Spring MVC uses Ajax to submit requests asynchronously to complete login
- Java Running Error: Could not find or load main class
- Conversion of two data types in Java
- [How to Solve]Repeated column in mapping for entity,should be mapped with insert=“false“ update=“false“
- The number of control threads and concurrency number of concurrent executor of Java starting gun
- Springboot controls the startup of rabbitmq through configuration files
- [Fixed] Disgusting bug Error:Failed to Load project configuration: cannot parse filemessage: content is not allowed in the preface.
- The precision of decimal calculation with double and float in Java is not accurate
- How to Fix log4j2 warning: warn unable to identify org.fusesource.jansi.WindowsAnsiOutputStream