zoukankan      html  css  js  c++  java
  • 插入po得到主键,插入sql得到主键

    import com.yd.common.data.CIPPageInfo;
    import com.yd.common.data.CIPReqCondition;
    import com.yd.common.exception.CIPDaoException;
    import com.yd.common.runtime.CIPErrorCode;
    import com.yd.wms.busi.dao.impl.WMS_busi_outboundDaoImpl;
    import com.yd.wms.busi.data.WMS_busi_outboundData;
    import com.yd.wms.busi.data.po.WMS_busi_outboundPO;
    
    import java.util.List;
    import java.util.Map;
    
    import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
    import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
    import org.springframework.jdbc.support.KeyHolder;
    import org.springframework.stereotype.Repository;
    
    
    
        public int addData(WMS_busi_outboundPO po) {            
            SimpleJdbcInsert insertActor = new SimpleJdbcInsert(jdbcTemplate).withTableName("riv_outbound_notice_h").usingGeneratedKeyColumns("ONH_ID");
            try{
                KeyHolder keyHolder = insertActor.executeAndReturnKeyHolder(new BeanPropertySqlParameterSource(po));
                 return keyHolder.getKey().intValue();
            }catch(Exception e) {
                log.error(e);
                throw new CIPDaoException(CIPErrorCode.ERROR_DATABASE_TECH_EXCEPTION);
            }
         }
    import org.springframework.dao.InvalidDataAccessApiUsageException;
    import org.springframework.jdbc.core.BatchPreparedStatementSetter;
    import org.springframework.jdbc.core.BeanPropertyRowMapper;
    import org.springframework.jdbc.core.PreparedStatementCreator;
    import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
    import org.springframework.jdbc.support.GeneratedKeyHolder;
    import org.springframework.jdbc.support.KeyHolder;
    
    KeyHolder keyHolder = new GeneratedKeyHolder();
            jdbcTemplate.getJdbcOperations().update(new PreparedStatementCreator() {
                public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
                    PreparedStatement ps = con.prepareStatement(OmsSqlConstants.SAVE_MATERIAL_FOR_QM, new String[] {"mat_id"});
                    ps.setString(1, materialProxy.getRivMaterial().getMatCode());
                    ps.setInt(2, materialProxy.getRivMaterial().getMatOwnerId());
                    ps.setString(3, materialProxy.getRivMaterial().getMatName());
                    ps.setString(4, materialProxy.getRivMaterial().getMatShortName());
                    ps.setString(5, materialProxy.getRivMaterial().getMatEnName());
                    ps.setString(6, materialProxy.getRivMaterial().getMatSpec());
                    ps.setString(7, materialProxy.getRivMaterial().getMatBarcode());
                    ps.setString(8, materialProxy.getRivMaterial().getMatBasicUomName());
                    ps.setBigDecimal(9, materialProxy.getRivMaterial().getMatShelfLifeDays());
                    ps.setInt(10, materialProxy.getRivMaterial().getMatIsFragile());
                    ps.setInt(11, materialProxy.getRivMaterial().getStatus());
                    ps.setTimestamp(12, new Timestamp(System.currentTimeMillis()));
                    ps.setInt(13, SecurityContextHelper.getCurrentUserId());
                    ps.setString(14, materialProxy.getRivMaterial().getMatInternalBarcode());
                    ps.setString(15, materialProxy.getRivMaterial().getGenMethod());
                    ps.setInt(16, SecurityContextHelper.getCurrentUserId());
                    ps.setString(17, materialProxy.getRivMaterial().getMatSkc());
                    return ps;
                }
            }, keyHolder);
    
    /** 物料表记录保存 **/
        public final static String SAVE_MATERIAL_FOR_QM = "insert into riv_material 
    " +
                "    (mat_code, mat_owner_id, mat_name, mat_short_name, mat_en_name, mat_spec, 
    " +
                "    mat_barcode, mat_basic_uom_name, mat_shelf_life_days, mat_is_fragile, status, create_time, 
    " +
                "    create_user_id, MAT_INTERNAL_BARCODE, GEN_METHOD, update_user_id,mat_skc) " +
                "    values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?) ";
  • 相关阅读:
    博客园的自定义皮肤
    为自己的审美观感到惭愧
    关于GitHub的Hello Word
    使用Windows Live Writer撰写的第一篇博文
    正式入驻博客园了
    一个使用 Web Components 的音乐播放器: MelodyPlayer
    一个(伪)MaterialDesign风格的博客园皮肤
    从零开始,做一个NodeJS博客(一):Heroku上的最简NodeJS服务器
    从零开始,做一个NodeJS博客(零):整体规(chui)划(niu)
    在 Xamarin.Android 中使用 Notification.Builder 构建通知
  • 原文地址:https://www.cnblogs.com/tonggc1668/p/6434452.html
Copyright © 2011-2022 走看看