MyBatis-Oracle-selectKey返回主键

插入类目记录,并返回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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值