新增SQL
selectKey标签中加keyProperty="id" order="AFTER"
<insert id="insert" parameterType="cn.crm.domain.TMeal">
<selectKey resultType="java.lang.Long" keyProperty="id" order="AFTER" >
SELECT LAST_INSERT_ID()
</selectKey>
insert into t_meal (name, price,
exprie_date, status)
values (#{name,jdbcType=VARCHAR}, #{price,jdbcType=DECIMAL},
#{exprieDate,jdbcType=TIMESTAMP}, #{status,jdbcType=BIT})
</insert>
使用
调用新增方法后即可获取主键
tmealService.save(tMeal); System.out.println(tMeal.getId() + "------");