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数据它回返回到传入的对象属性里




















  • 相关阅读:
    App提交Appstore审核流程【转】
    程序员必须软件
    Linux的cron和crontab
    Git操作基本命令
    Python编码问题整理【转】
    Python读取ini配置文件
    RF+Jenkins构建持续集成
    RF接口测试本地环境部署
    Python建立SSH连接与使用方法
    永久修改python默认的字符编码为utf-8
  • 原文地址:https://www.cnblogs.com/spll/p/9628128.html
Copyright © 2011-2022 走看看