<insert id="add" parameterType="com.dsa.core.base.model.ProductSync">
        insert into tm_sync_product(
            <if test="productId!=null">product_id,</if>
            <if test="mainLimit!=null">main_limit,</if>
            <if test="productName!=null">product_name,</if>
            <if test="productBrand!=null">product_brand,</if>
            <if test="profitType!=null">profit_type,</if>
            <if test="deadLine!=null">dead_line,</if>
            <if test="productStartDay!=null">product_start_day,</if>
            <if test="productEndDay!=null">product_end_day,</if>
            <if test="buyStartDay!=null">buy_start_day,</if>
            <if test="buyEndDay!=null">buy_end_day,</if>
            <if test="riskRank!=null">risk_rank,</if>
            <if test="redeemFlg!=null">redeem_flg,</if>
            <if test="productStatus!=null">product_status,</if>
            <if test="startAmount!=null">start_amount,</if>
            <if test="addAmount!=null">add_amount,</if>
            <if test="yearRate!=null">year_rate,</if>
            <if test="productNote!=null">product_note,</if>
            <if test="otherBankBuy!=null">other_bank_buy,</if>
            <if test="otherBankAmt!=null">other_bank_amt,</if>
            <if test="rateVal!=null">rate_val,</if>
            <if test="recordFlg!=null">record_flg</if>
        ) values (
            <if test="productId!=null">#{productId},</if>
            <if test="mainLimit!=null">#{mainLimit},</if>
            <if test="productName!=null">#{productName},</if>
            <if test="productBrand!=null">#{productBrand},</if>
            <if test="profitType!=null">#{profitType},</if>
            <if test="deadLine!=null">#{deadLine},</if>
            <if test="productStartDay!=null">#{productStartDay},</if>
            <if test="productEndDay!=null">#{productEndDay},</if>
            <if test="buyStartDay!=null">#{buyStartDay},</if>
            <if test="buyEndDay!=null">#{buyEndDay},</if>
            <if test="riskRank!=null">#{riskRank},</if>
            <if test="redeemFlg!=null">#{redeemFlg},</if>
            <if test="productStatus!=null">#{productStatus},</if>
            <if test="startAmount!=null">#{startAmount},</if>
            <if test="addAmount!=null">#{addAmount},</if>
            <if test="yearRate!=null">#{yearRate},</if>
            <if test="productNote!=null">#{productNote},</if>
            <if test="otherBankBuy!=null">#{otherBankBuy},</if>
            <if test="otherBankAmt!=null">#{otherBankAmt},</if>
            <if test="rateVal!=null">#{rateVal},</if>
            <if test="recordFlg!=null">#{recordFlg}</if>
        )
        <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
             select last_insert_id() as id
        </selectKey>
    </insert>
注意:(此处为mysql)这里的selectKey的resultType 必须和实体对象中的id类型一致,否则报错。

oracle的如下:

<selectKey resultType="java.lang.Long" keyProperty="ID" order="AFTER">
SELECT IBOKEE_COMM_TAG_LIBRARY_SEQ.nextval AS Id FROM DUAL
</selectKey>

实体类
public class ProductSync implements Serializable {
         private Long id;
         ...
         ...

}

dao Mapper
public interface ProductSyncMapper {
   
    /**
     * @param product Object
     * 新增纪录
     */
    public void add(ProductSync product);
   
   
}

Mybatis插入数据返回主键ID的更多相关文章

  1. MyBatis框架——mybatis插入数据返回主键(mysql、oracle)

    向数据库中插入数据时,大多数情况都会使用自增列或者UUID做为主键.主键的值都是插入之前无法知道的,但很多情况下我们在插入数据后需要使用刚刚插入数据的主键,比如向两张关联表A.B中插入数据(A的主键是 ...

  2. mybatis插入是返回主键id

    <!-- 插入数据:返回记录的id值 --> <insert id="insertOneTest" parameterType="org.chench. ...

  3. 关于mybatis插入数据库返回主键id

    关于Sequence主键的数据库来说,如: <insert id="add" parameterType="vo.Category"> <se ...

  4. mybatis插入数据返回主键

    原来之前一直用错了... keyProperty是表示将返回的主键设置为该方法参数的对应属性中去,而不是用返回值的形式的去获取.

  5. Mybatis配置插入数据返回主键ID

    需要在insert方法中添加 <insert id="insertSelective" parameterType="com.midou.ott.model.MDA ...

  6. Java MyBatis 插入数据库返回主键

    最近在搞一个电商系统中由于业务需求,需要在插入一条产品信息后返回产品Id,刚开始遇到一些坑,这里做下笔记,以防今后忘记. 类似下面这段代码一样获取插入后的主键 User user = new User ...

  7. MyBatis 插入数据库返回主键

    最近在搞一个电商系统中由于业务需求,需要在插入一条产品信息后返回产品Id,刚开始遇到一些坑,这里做下笔记,以防今后忘记. 类似下面这段代码一样获取插入后的主键 User user = new User ...

  8. Java MyBatis 插入数据库返回主键--insertSelective这样就不用每次到数据库里面查询了

    insertSelective---Java MyBatis 插入数据库返回主键--insertSelective这样就不用每次到数据库里面查询了 https://www.cnblogs.com/xi ...

  9. myBatis获取批量插入数据的主键id

    在myBatis中获取刚刚插入的数据的主键id是比较容易的 , 一般来说下面的一句话就可以搞定了 , 网上也有很多相关资料去查. @Options(useGeneratedKeys = true, k ...

随机推荐

  1. Django REST framework+Vue 打造生鲜超市(十三)

    目录 生鲜超市(一)    生鲜超市(二)    生鲜超市(三) 生鲜超市(四)    生鲜超市(五)    生鲜超市(六) 生鲜超市(七)    生鲜超市(八)    生鲜超市(九) 生鲜超市(十) ...

  2. 1、原生javascript方法小汇

    Js 对象 使用new 关键字来创建对象,举例如下, var a = new String();如构造函数无参数,则不必加括号, JS内部对象数组(Array)对象创建数组var myarray = ...

  3. tomcat 构建问题记录

    mvng构建程序包com.sun.image.codec.jpeg不存在------->缺少serlet的jar包 MasterSlaveRoutingDataSource不是抽象的, 并且未覆 ...

  4. ubuntu18.04安装安装JDK

    1.前提准备: 下载JDK:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 2. ...

  5. 配置teredo,启用ipv6,xx-net

    最近使用XX-NET科学上网 ,提示要配置使用IPv6.根据github的上win10配置ipv6方式(https://github.com/XX-net/XX-Net/wiki/IPv6-Win10 ...

  6. 指针超强汇总(谨记优先级:() > [] > *)

    参考:http://blog.chinaunix.net/uid-20120277-id-5760985.html C语言所有复杂的指针声明,都是由各种声明嵌套构成的.如何解读复杂指针声明呢?右左法则 ...

  7. PAT1116: Come on! Let's C

    1116. Come on! Let's C (20) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue &quo ...

  8. 手把手教你创建「人物角色Persona」

    一.为什么要创建人物角色 下图来自 Cooper interaction design ,同样有购车需求的用户,用车的人不同.各自的目的不同,最终满足需求的车型也有很大差异.对于汽车公司而言,在车辆设 ...

  9. 基于 WebRTC 创建一款多人联机游戏

    本项目的目标旨在尽可能少用服务器资源的前提下研发一款在线多人游戏,同时期望在一个用户的浏览器上运行游戏,同时让另一个玩家来连接.此外还希望程序尽可能简单以便于在博客中分析. 运用的技术 在我刚接触 P ...

  10. 深入浅出javascript学习笔记

    弱类型的隐式转换: 32 + 32 // 64 "32" + 32 // "3232" "32" – 32 // 0 巧用+/-规则转换类型 ...