欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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="" 这个属性指向传递的参数实体类