zoukankan      html  css  js  c++  java
  • mybaits返回插入成功后的自增值

    mybaits返回插入成功后的自增值

    在项目中,我们经常遇到这样的情况:insert语句成功后,需要自增的id值,这个时候,我们可以通过mybatis的 useGeneratedKeys 来实现,具体如下:

       <!--新增巡检预案-->
        <insert id="insertVideoFormPolling" useGeneratedKeys="true" keyProperty="pollingPlan.pollingPlanId" parameterType="com.unisits.zngkpt.data.pollingmandata.pojo.PollingPlan" >
          INSERT INTO polling_plan(polling_plan_type,unit_id,polling_plan_name,polling_plan_desc)
          VALUES (1,${pollingPlan.unitId},#{pollingPlan.pollingPlanName},#{pollingPlan.pollingPlanDesc})
        </insert>

    在这里,useGeneratedKeys 代表这个表的id是自增的,keyProperty属性指定,哪列是自增的,那么怎么获取自增的id呢?

    public void addVideoFormPolling(){
    PollingPlan pp = new PollingPlan();
    pp.setPollingPlanName("test23");
    pp.setUnitId(1000);
    pp.setPollingPlanDesc("test");
    int result = pollingVideoDao.insertVideoFormPolling(pp);
    System.out.println(pp.getPollingPlanId()+"--"+result);
    }

    而这里的 pp.getPollingPlanId() 就是获取的返回值的id

  • 相关阅读:
    Java正则表达式教程及示例
    MySQL 事务
    MySQL 正则表达式
    常用函数 __MySQL必知必会
    使用MySQL正则表达式 __MySQL必知必会
    首先使用flex制作table
    javascript原生调用摄像头
    网页背景图片随机
    网页背景视频的实现
    网站无法显示logo?
  • 原文地址:https://www.cnblogs.com/ningheshutong/p/8126641.html
Copyright © 2011-2022 走看看