自己添加的话,是这样:
<insert id="insert" parameterType="cn.xxxx.bean.Subtask" useGeneratedKeys="true" keyProperty="id"> insert... </insert>
麻烦,自动生成的话,这样:
<table schema="cc" tableName="test" domainObjectName="TT" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> <generatedKey column="id" sqlStatement="MySql" identity="true"/> </table>
这个是mysql的写法。
更多,请看官方文档: http://mybatis.org/generator/configreference/generatedKey.html ------------------------------------------ 几种方式对比: (1)<generatedKey column="id" sqlStatement="MySql"/>
<insert id="insert" parameterType="com.shijie99.order.common.domain.SqlExceptionLog"> <selectKey keyProperty="id" order="BEFORE" resultType="java.lang.Integer"> SELECT LAST_INSERT_ID() </selectKey> insert...
(2)<generatedKey column="id" sqlStatement="MySql" identity="true"/>
<insert id="insert" parameterType="com.shijie99.order.common.domain.SqlExceptionLog"> <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Integer"> SELECT LAST_INSERT_ID() </selectKey> insert...
(3)<generatedKey column="id" sqlStatement="JDBC"/>
<insert id="insert" keyProperty="id" parameterType="com.shijie99.order.common.domain.SqlExceptionLog" useGeneratedKeys="true"> insert.. </insert>
mysql应该使用(2)(3)两种,使用(1)是不对的~~~
|