主键回填
insert配置字段:
id:和命名空间组合作为唯一标识
keyProperty:主键列名,联合组建则以分号分隔
useGeneratedKeys:是否内部生成主键
keyColumn:主键是第几列
例子:(role有id,roleName,note三个属性)
<insert id="insertRole" parameterType="role" useGeneratedKeys="true"
keyProperty="id">
insert into t_role (role_name,note) values (#{roleName},#{note})
</insert>
自定义
<insert id="insertRole" parameterType="role" useGeneratedKeys="true"
keyProperty="id">
<selectKey keyProperty="id" resultType="int" order=""BEFORE>
select if(max(id) is null,1,max(id)+2) as newId from t_role
</selectKey>
insert into t_role (id,role_name,note) values (#{id},#{roleName},#{note})
</insert>
时间: 2024-10-19 13:28:28