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;
}

mysql插入返回当前生成的主键的更多相关文章

  1. Mybatis 插入一条或批量插入 返回带有自增长主键记录

    首先讲一下,  插入一条记录返回主键的 Mybatis 版本要求低点,而批量插入返回带主键的 需要升级到3.3.1版本,3.3.0之前的都不行, <dependency> <grou ...

  2. mybatis+oracle 完成插入数据库,并将主键返回的注意事项

    mybatis+oracle 完成插入数据库,并将主键返回的注意事项一条插入语句就踩了不少的坑,首先我的建表语句是: create table t_openapi_batch_info( BATCH_ ...

  3. MySQL数据表中有自增长主键时如何插入数据

    原文链接:https://blog.csdn.net/RuobaiMEN/article/details/79794199 MySQL数据库表中有自增主键ID,当用SQL插入语句中插入语句带有ID列值 ...

  4. javaweb学习总结(三十七)——获得MySQL数据库自动生成的主键

    测试脚本如下: 1 create table test1 2 ( 3 id int primary key auto_increment, 4 name varchar(20) 5 ); 测试代码: ...

  5. javaweb(三十七)——获得MySQL数据库自动生成的主键

    测试脚本如下: 1 create table test1 2 ( 3 id int primary key auto_increment, 4 name varchar(20) 5 ); 测试代码: ...

  6. 获取mysql自主生成的主键

    一.sql语句 CREATE TABLE `testgeneratedkeys` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(20) ...

  7. 五.获得MYSQL数据库自动生成的主键

    测试脚本如下: 1 create table test1 2 ( 3 id int primary key auto_increment, 4 name varchar(20) 5 ); 测试代码: ...

  8. (jdbc)取得数据库自动生成的主键方法

    一些类,在前面的博客中有,就不重复了 public class Test2 { TestDAO t=new TestDAO(); /*前提是数据表的主键是自动增加的, *取得数据库自动生成的主键 * ...

  9. MyBatis插入时获取自增长主键

    在某些场景下,我们需要使用mybatis返回生成的主键值.Mybatis在insert和update标签中就提供了这种功能. 方法1: <insert id=”indetifyId” useGe ...

随机推荐

  1. Android 6.0 闪光灯的使用

    Android6.0 已经抛弃了Camer 相关的API,改用新的API接口CamerManager,下面给出使用的简单实例 package com.inper.duqiang.slashlight; ...

  2. (原创)ubuntu 12.04 安装 apache ant

    1. go to the websie to download the newest version of ant (search google by "Apache Ant"). ...

  3. Lucene学习总结之一:全文检索的基本原理

    一.总论 根据http://lucene.apache.org/java/docs/index.html 定义: Lucene 是一个高效的,基于Java 的全文检索库. 所以在了解Lucene之前要 ...

  4. c#或获取系统的特殊路径,如我的文档等

    Console.WriteLine(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)); System.E ...

  5. C#解析JSON数据

    本篇文章主要介绍C#对Json数据的读取. 主要操作过程是: 发送Http请求获取Json数据 把获取的Json数据转换成C#中的类 下面我们以12306火车票余票的数据为例进行切入. 首先来看一下h ...

  6. 使用jekyll和prose在github上创建博客

    利用github的pages服务可以很方便地显示和管理我们的静态页面,这样用来做博客是非常适合的. 1.首先你要有一个github的帐号 2.创建一个repo,名字叫username.github.i ...

  7. jQuery之事件

    (一).事件列表. 1.blur() 当失去焦点时触发.包括鼠标点击离开和TAB键离开. 2.change() 当元素获取焦点后,值改变失去焦点事触发. 3.click() 当鼠标单击时触发. 4.d ...

  8. 扩展ArcGIS API for Silverlight/WPF 中的TextSymbol支持角度标注

    原文 http://blog.csdn.net/esricd/article/details/7587136 在ArcGIS API for Silverlight/WPF中原版的TextSymbol ...

  9. ## GridView 布局:item设置的高度和宽度不起作用、自动适配列数、添加Header和Footer ##

    一.item设置的高度和宽度不起作用 转自:http://www.cnblogs.com/0616--ataozhijia/p/6031875.html [Android Pro] listView和 ...

  10. POJ 3997 Stock Chase

    Stock Chase Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 455   Accepted: 131 Descrip ...