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>
  • 相关阅读:
    Arduino
    DTU
    现代信号处理与应用
    matlab学习记录
    列车准点节能操纵
    泊松过程
    序号生成算法odoo
    操作系统特性
    c语言中的变量
    xml中的四则运算与时间爱格式
  • 原文地址:https://www.cnblogs.com/xiaozhang666/p/13503111.html
Copyright © 2011-2022 走看看