<insert id="insert" parameterType="com.mall.model.Depart" keyProperty="id" useGeneratedKeys="true">
insert into depart (id, name, parentId,
level, seq, remark,
operator, operatorTime, operatorIp
)
values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{parentid,jdbcType=INTEGER},
#{level,jdbcType=VARCHAR}, #{seq,jdbcType=INTEGER}, #{remark,jdbcType=VARCHAR},
#{operator,jdbcType=VARCHAR}, #{operatortime,jdbcType=TIMESTAMP}, #{operatorip,jdbcType=VARCHAR}
)
</insert>
添加:keyProperty="id" useGeneratedKeys="true" 这两个属性,就可以在实现插入后返回插入的id
第二种
//插入完成后获取id
@Insert("insert into order_info(user_id, goods_id, goods_name, goods_count, goods_price, order_channel, status, create_date)values("
+ "#{userId}, #{goodsId}, #{goodsName}, #{goodsCount}, #{goodsPrice}, #{orderChannel},#{status},#{createDate} )")
@SelectKey(keyColumn="id", keyProperty="id", resultType=long.class, before=false, statement="select last_insert_id()")
public long insert(OrderInfo orderInfo);