zoukankan      html  css  js  c++  java
  • mybatis插入数据并返回自增Id

    上图mybatis的写法,在xxxMapper.xml中:

    加入:useGeneratedKeys="true" keyProperty="applyId" keyColumn="apply_id"

    <insert id="insertSelective2" parameterType="com.xxx.model.vo.DlglMaterielVo"  useGeneratedKeys="true" keyProperty="applyId" keyColumn="apply_id">
     insert into dlgl_materiel (apply_id, agent_id, create_account_id,
      create_time, status, remark, 
    post_user_id, post_time, post_code,
    receiver_address, receiver_user, post_remark
    )
    values (#{applyId,jdbcType=INTEGER}, #{agentId,jdbcType=VARCHAR}, #{createAccountId,jdbcType=VARCHAR},
    #{createTime,jdbcType=TIMESTAMP}, #{status,jdbcType=INTEGER}, #{remark,jdbcType=VARCHAR},
    #{postUserId,jdbcType=VARCHAR}, #{postTime,jdbcType=TIMESTAMP}, #{postCode,jdbcType=VARCHAR},
    #{receiverAddress,jdbcType=VARCHAR}, #{receiverUser,jdbcType=VARCHAR}, #{postRemark,jdbcType=VARCHAR}
    )
    </insert>
    》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》
    这里有件很坑的事,我在网上找这个方法的时候好多人都没有写出来。

    就是我以为它回直接返回这个自增的id字段,然后我用一个Integer接收,靠调bug调了半天,才发现它是直接把这个字段返回给传入的对象里
    所以使用这个插入方法根本不用东西去接收自增字段,直接调用便可,所要的自增id数据它回返回到传入的对象属性里




















  • 相关阅读:
    第009讲:了不起的分支和循环3
    Term_Application
    十大编程算法助程序员走上高手之路
    每天工作4小时的程序员
    编程真相_节选
    Sublime_Snippet
    VIM资源管理
    微信企业号开发资源整理
    vitruviano
    VIM_git
  • 原文地址:https://www.cnblogs.com/spll/p/9628128.html
Copyright © 2011-2022 走看看