<insert id="save" parameterType="com.itheima.domain.User">
-- selectKey:回显主键
-- resultType: 返回值类型
-- keyColumn: 主键列名
-- keyProperty:主键属性名
-- order: 在insert语句之前查询,还是之后查询
-- last_insert_id : 该表在最后一次添加时生成的主键id
<selectKey resultType="java.lang.Integer" keyColumn="id" keyProperty="id" order="AFTER">
select last_insert_id()
</selectKey>
insert into t_user values(null, #{username},#{age} )
</insert>
`需要注意的是 :
1. mapper层接口中对应方法的参数前不能使用@Param注解
例: void save(User user) user前不能使用@Param注解
2. 对应的实体类中主键id必须满足自增条件
(切记-->数据库中主键id不能为varchar类型)
Mybatis框架--添加完成后主键回显
最新推荐文章于 2024-06-09 12:23:17 发布