码迷,mamicode.com
首页 > 其他好文 > 详细

mybatis新增数据后获取自增主键

时间:2016-06-01 15:28:09      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:

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>

 

mybatis新增数据后获取自增主键

标签:

原文地址:http://www.cnblogs.com/zrui-xyu/p/5549615.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!