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