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赋值给相应的对象

posted @ 2018-01-19 21:40  在谷歌上百度  阅读(900)  评论(0编辑  收藏  举报