<!--
last_insert_id() : 查询刚插入数据自增 id
order : 执行的时机: after 之前执行; before 之后执行
keyProperty : 与实体类属性保持一致
keyColumn : 与数据库字段保持一致
-->
<insert id="save" parameterType="orders" >
<selectKey keyProperty="id" keyColumn="id" resultType="int" order="AFTER" >
select last_insert_id();
</selectKey>
insert into orders value(null, #{ordertime}, #{total}, #{uid})
</insert>
@Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
@Insert("insert into orders values(null, #{ordertime}, #{total}, #{uid})")
Integer insert(Orders orders);
// 实体类对象,属性值省略
Orders orders;
// 插入,返回值为影响的行数
Integer rows = sqlSession.getMapper(OrdersDao.class).insert(orders);
// id 需要通过实体类对象获取
Long id = orders.getId()