插入sql返回主键id

1 <insert id="insertSelective" parameterType="com.xxx.model.XDetail" useGeneratedKeys="true" keyProperty="id">

主要依靠useGeneratedKeys="true" keyProperty="id"实现

原文地址:https://www.cnblogs.com/locker777/p/10084122.html

时间: 2024-07-29 16:06:50

插入sql返回主键id的相关文章

关于mybatis插入数据库返回主键id

关于Sequence主键的数据库来说,如: <insert id="add" parameterType="vo.Category"> <selectKey resultType="java.lang.Short" order="BEFORE" keyProperty="id"> SELECT SEQ_TEST.NEXTVAL FROM DUAL </selectKey>

Mybatis配置插入数据返回主键ID

需要在insert方法中添加 <insert id="insertSelective" parameterType="com.midou.ott.model.MDActivity" useGeneratedKeys="true" keyProperty="id"> 加上上面红色部分,keyProperty中的id,是MDActivity对象的中的Id 使用时直接从MDActivity对象中获取到ID

Mybatis插入数据返回主键ID

<insert id="add" parameterType="com.dsa.core.base.model.ProductSync">        insert into tm_sync_product(            <if test="productId!=null">product_id,</if>            <if test="mainLimit!=null&q

SQL 用于插入返回主键ID,一般和事务用在一起

一个例子保存的例子,用于插入返回主键ID--创建人:By justin Create PROC [dbo].[SaveCustomer] ( @CustomerName varchar(500), @pID int ) as Begin --插入数据 Insert Into Customer( CustomerName, pID ) values( @CustomerName , @pID ) select SCOPE_IDENTITY() End SQL 用于插入返回主键ID,一般和事务用在一

MyBatis+MySQL 返回插入记录的主键ID

今天用到了多个表之间的关系,另一个表中的一个字段要以第一个表的主键作为外键. 下面说两种方法,MyBatis+MySQL 返回插入记录的主键ID: 第一种: <insert id="insertAndGetId" useGeneratedKeys="true" keyProperty="userId" parameterType="com.chenzhou.mybatis.User"> insert into us

Oracle 在函数或存储过程中执行一条插入语句并返回主键ID值

有时,我们需要往一张表插入一条记录,同时返回主键ID值. 假定主键ID的值都是通过对应表的SEQUENCE来获得,然后进行ID赋值 这里有几种情况需要注意: 1)如果建表语句含有主键ID的触发器,通过触发器来实现主键ID的自增,实现方式如下: INSERT INTO GP_MONTH_BILL ( MONTH, BONUS_VALUE, CUR_WAY, CUR_TIME, STATUS, IS_USE, CREATE_TIME) VALUES ( CUR_MONTH, CUR_BONUS_VA

解决getJdbcTemplate往oracle数据库中插入数据返回主键出错问题

我们使用Spring中的JdbcDaoSupport往Mysql中插入数据并返回主键代码,我们使用的mysql数据库,主键在数据库中设置为自增长:该类继承自JdbcDaoSupport,所以能直接使用getJdbcTemplate() public int saveUser(String userName,int age,String password){ getJdbcTemplate().update(new PreparedStatementCreator() { public Prepa

开启事务时mybatis返回主键id

先说一下没有注解的 先给出实体类: public class City { private int city_id; private String city_name; public int getCity_id() { return city_id; } public void setCity_id(int city_id) { this.city_id = city_id; } public String getCity_name() { return city_name; } public

Mybatis中insert中返回主键ID的方法

1.XyzMapper.xml <insertid="doSomething"parameterType="map"useGeneratedKeys="true"keyProperty="yourId"> ... </insert> 或 <insert id="doSomething" parameterType="com.xx.yy.zz.YourClass&quo