zoukankan      html  css  js  c++  java
  • mybatis新增数据后获取自增主键

    mybatis对应mysql

    <insert id="insert" parameterType="com.timestech.wsgk.web.model.SysOrg" useGeneratedKeys="true">           --------------即可获取service中实体类的自增ID
          
        insert into BJLT.SYS_ORG (ID, NAME, P_ID, 
          P_NAME, REMARK, LEVELS, 
          STATUS, CREATE_TIME, CREATE_ID, 
          CREATE_NAME, UPDATE_TIME, UPDATE_ID, 
          UPDATE_NAME, TREE_PATH, RESERVE1, 
          RESERVE2, RESERVE3, RESERVE4, 
          RESERVE5, IS_ROOT, IS_BUILT_IN
          )
        values (#{id,jdbcType=DECIMAL}, #{name,jdbcType=VARCHAR}, #{pId,jdbcType=DECIMAL}, 
          #{pName,jdbcType=VARCHAR}, #{remark,jdbcType=VARCHAR}, #{levels,jdbcType=DECIMAL}, 
          #{status,jdbcType=DECIMAL}, #{createTime,jdbcType=DATE}, #{createId,jdbcType=VARCHAR}, 
          #{createName,jdbcType=VARCHAR}, #{updateTime,jdbcType=DATE}, #{updateId,jdbcType=VARCHAR}, 
          #{updateName,jdbcType=VARCHAR}, #{treePath,jdbcType=VARCHAR}, #{reserve1,jdbcType=VARCHAR}, 
          #{reserve2,jdbcType=VARCHAR}, #{reserve3,jdbcType=VARCHAR}, #{reserve4,jdbcType=VARCHAR}, 
          #{reserve5,jdbcType=VARCHAR}, #{isRoot,jdbcType=DECIMAL}, #{isBuiltIn,jdbcType=DECIMAL}
          )
      </insert>

    mybatis对应oracle

    <insert id="insert" parameterType="com.timestech.wsgk.web.model.SysOrg" >
          <selectKey keyProperty="id" resultType="_long" order="BEFORE">            -------------------获取oracle的自增序列,在新增之前先赋值
            SELECT BJLT.SYS_ORG_SEQUENCE.Nextval from DUAL
          </selectKey>
        insert into BJLT.SYS_ORG (ID, NAME, P_ID, 
          P_NAME, REMARK, LEVELS, 
          STATUS, CREATE_TIME, CREATE_ID, 
          CREATE_NAME, UPDATE_TIME, UPDATE_ID, 
          UPDATE_NAME, TREE_PATH, RESERVE1, 
          RESERVE2, RESERVE3, RESERVE4, 
          RESERVE5, IS_ROOT, IS_BUILT_IN
          )
        values (#{id,jdbcType=DECIMAL}, #{name,jdbcType=VARCHAR}, #{pId,jdbcType=DECIMAL}, 
          #{pName,jdbcType=VARCHAR}, #{remark,jdbcType=VARCHAR}, #{levels,jdbcType=DECIMAL}, 
          #{status,jdbcType=DECIMAL}, #{createTime,jdbcType=DATE}, #{createId,jdbcType=VARCHAR}, 
          #{createName,jdbcType=VARCHAR}, #{updateTime,jdbcType=DATE}, #{updateId,jdbcType=VARCHAR}, 
          #{updateName,jdbcType=VARCHAR}, #{treePath,jdbcType=VARCHAR}, #{reserve1,jdbcType=VARCHAR}, 
          #{reserve2,jdbcType=VARCHAR}, #{reserve3,jdbcType=VARCHAR}, #{reserve4,jdbcType=VARCHAR}, 
          #{reserve5,jdbcType=VARCHAR}, #{isRoot,jdbcType=DECIMAL}, #{isBuiltIn,jdbcType=DECIMAL}
          )
      </insert>
  • 相关阅读:
    使用 gpg 加密文件
    CodeIgniter-Lottery
    使用phpize安装php扩展
    myWaterfall
    一台电脑上的git同时使用两个github账户
    移动端上传照片 预览+Draw on Canvas's Demo(解决 iOS 等设备照片旋转 90 度的 bug)
    移动端禁止页面下滑
    移动端用js与jquery实时监听输入框值的改动
    不管人生怎么走,都需要实时回头看看
    Shader 入门笔记(二) CPU和GPU之间的通信,渲染流水线
  • 原文地址:https://www.cnblogs.com/zrui-xyu/p/5549615.html
Copyright © 2011-2022 走看看