zoukankan      html  css  js  c++  java
  • MyBatis在insert时返回自增长id值(两种)

      <!--
          返回主键,方式一 useGeneratedKeys属性
          useGeneratedKeys="true" 开启新增主键返回功能
          keyColumn="id" user表中主键列
          keyProperty="id" user实体主键属性
          注意:仅支持主键自增类型的数据库 MySQL 和 SqlServer , oracle不支持
      -->
      <insert id="save1" parameterType="User" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
         insert into user(username,birthday,sex,address) values(#{username},#{birthday},#{sex},#{address})
      </insert>
      <!--
          返回主键,方式二 <selectKey>
          keyColumn="id" user表中主键列
          keyProperty="id" user实体主键属性
          resultType="int" user实体主键属性类型
          order="AFTER" 表示此标签内部sql语句在insert执行之前(执行),还是之后执行(执行)
            AFTER 之后执行【在自增主键时】
            BEFORE 之前执行【使用指定主键时】
      -->
      <insert id="save2" parameterType="User" >
        <selectKey keyColumn="id" keyProperty="id" resultType="int" order="AFTER">
          SELECT LAST_INSERT_ID()
        </selectKey>
       insert into user(username,birthday,sex,address) values(#{username},#{birthday},#{sex},#{address})
      </insert>
  • 相关阅读:
    shell中对于命令的搜寻顺序
    在shell中运行以不同方式运行脚本
    shell中的type命令
    shell中的数组
    shell中的循环语句
    shell中的case表达式
    双方括号
    34. Win7_x64安装oracle11g出现DIM-00019
    33. 完全卸载oracle11g步骤
    32. 安装oracle11g时,先决条件一直失败的解决方法
  • 原文地址:https://www.cnblogs.com/xiaozhang666/p/13503111.html
Copyright © 2011-2022 走看看