Mybatis设置主键自增
<insert id="insertArea" useGeneratedKeys="true" keyProperty="areaId" keyColumn="area_id"> INSERT INTO tb_area(area_name,area_desc,priority, create_time,last_edit_time) VALUES (#{areaName},#{areaDesc},#{priority}, #{createTime},#{lastEditTime}) </insert>
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <!-- 配置全局属性 --> <settings> <!-- 使用jdbc的getGeneratedKeys获取数据库自增主键值 --> <setting name="useGeneratedKeys" value="true" /> <!-- 使用列标签替换列别名 默认:true --> <setting name="useColumnLabel" value="true" /> <!-- 开启驼峰命名转换:Table{create_time} -> Entity{createTime} --> <setting name="mapUnderscoreToCamelCase" value="true" /> </settings> <plugins> <plugin interceptor="com.imooc.o2o.dao.split.DynamicDataSourceInterceptor"> </plugin> </plugins> </configuration>