插入类目记录,并返回category_id,其中category_id是根据自定义规则生成的
<insert id="insertSelective2" parameterType="com.imooc.model.ProductCategory">
insert into product_category(<include refid="Base_Save_List"/>)
values (#{productCategory.categoryName,jdbcType=VARCHAR},#{productCategory.categoryType,jdbcType=INTEGER})
<selectKey keyProperty='productCategory.categoryId' resultType='int' order='AFTER' >
select MAX(category_id) from product_category
</selectKey>
</insert>
使用方法
public Integer save(ProductCategory productCategory) {
System.out.println(categoryMapper.insertSelective2(productCategory));
int categoryId = productCategory.getCategoryId;
return categoryId;
}
上述代码实现了将MAX(category_id)存入'productCategory.categoryId,供大家参考
MyBatis-Oracle-selectKey返回主键https://my.oschina.net/merryyou/blog/1358372