Mybatis获取自增主键值

1.配置文件变化

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.dao.BookMapper"> <insert id="insertBook" useGeneratedKeys="true" keyProperty="id">
insert into book (title,price,publishDate) value(#{title},#{price},#{publishDate})
</insert> </mapper>

useGeneratedKeys :使用自增序列

keyProperty:将新增得到的id赋值给相应的对象

上一篇:hihoCoder #1445 : 后缀自动机二·重复旋律5


下一篇:MyBatis映射文件1(增删改、insert获取自增主键值)