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;
    }
  • 相关阅读:
    pytorch实现BiLSTM+CRF用于NER(命名实体识别)
    pytorch中如何处理RNN输入变长序列padding
    pytorch nn.LSTM()参数详解
    Pytorch的LSTM的理解
    转:pytorch版的bilstm+crf实现sequence label
    【Tensorflow】tf.nn.atrous_conv2d如何实现空洞卷积?膨胀卷积
    iOS iphone5屏幕适配 autosizing
    IOS文件存储小结
    IIS6_IIS7日志文件位置
    xcode中没有autoSizing的设置
  • 原文地址:https://www.cnblogs.com/vanl/p/5276956.html
Copyright © 2011-2022 走看看