zoukankan      html  css  js  c++  java
  • mysql插入返回当前生成的主键

     1:sql中需要添加属性 keyColumn="base_price_id" keyProperty="basePriceId" useGeneratedKeys="true"

    <insert id="insertBasePrice" parameterType="com.olymtech.bs.freight.trk.vo.BasePriceResultVO"

       keyColumn="base_price_id" keyProperty="basePriceId" useGeneratedKeys="true">

        insert into 
        truck_base_price (product_id, casenumber, base_price20, base_price40,remark)
        values 
        (#{productId,jdbcType=BIGINT}, #{casenumber,jdbcType=INTEGER}, #{basePrice20,jdbcType=DECIMAL}, #{basePrice40,jdbcType=DECIMAL},#{remark,jdbcType=VARCHAR})
      </insert>

    2:返回到对应的实体中,如果要取到,则:

    public Boolean addBasePrice(BasePriceResultVO basePriceResultVO)throws DataAccessException{
    Boolean resultFlag=false;
    try {
    //先查询产品表该产品是否存在
    Long productId = null;
    TruckProduct trkProduct = truckProductDao.selectProductByIds(basePriceResultVO);
    if(trkProduct == null){
    truckProductDao.insertBaseProduct(basePriceResultVO);
    productId = basePriceResultVO.getProductId();
    }else{
    productId = trkProduct.getProductId();
    }
    basePriceResultVO.setProductId(productId);
    //TODO需要调车队相关的接口(暂时写死)
    basePriceResultVO.setCasenumber(1);
    truckBasePriceDao.insertBasePrice(basePriceResultVO);
    Long basePriceId = basePriceResultVO.getBasePriceId();
    if(basePriceId != null){
    basePriceResultVO.setBasePriceId(basePriceId);
    basePriceResultVO.setOperationType(TruckUtil.ADD);
    Long resultId=truckBasePriceHistoryDao.insertTruckBasePriceHistory(basePriceResultVO);
    if(resultId!=null){
    resultFlag = true;
    }
    }
    } catch (Exception ex) {
    LOGGER.error("TruckBasePriceServiceImpl.addBasePrice异常" + ex);
    }
    return resultFlag;
    }
  • 相关阅读:
    C#微信开发
    3-4:字符串方法
    2-4-1 元组
    2-3-3 列表方法
    2-2-3:序列(字符串)乘法(p32)
    3-3字符串格式化(p47)
    2-2:分片
    2-1:Print date(p28)
    old.2.三次登录机会
    old.2.sum(1-2+3-4+...+99)
  • 原文地址:https://www.cnblogs.com/vanl/p/5276956.html
Copyright © 2011-2022 走看看