mybatis如和在插入数据库以后返回主键?
程序员文章站
2022-06-02 19:01:52
...
<insert id="insertRole" parameterType="com.coship.web.uc.model.Role" keyProperty="id" useGeneratedKeys="true">
insert into T_ROLE(NAME,MSG,CREATOR_ID,TYPE)
values (#{name},#{msg},#{creatorId},#{type})
</insert>
useGeneratedKeys="true" 表示给主键设置自增长
keyProperty="userId" 表示将自增长后的Id赋值给实体类中的Id字段。
parameterType="" 这个属性指向传递的参数实体类