如何获取mybatis insert 插入的id
配置了xml文件的 标签配置了:useGeneratedKeys=“true” keyProperty=“id”
<insert id="insert" parameterType="com.xxx.Goods" useGeneratedKeys="true" keyProperty="id">
insert into goods(NAME,AGE)
values
(#{name,jdbcType=VARCHAR},#{age,jdbcType=VARCHAR})
</insert>
使用
goodsMapper.insert(goods);
// 获取
Long id = goods.getId();