mybatis 插入返回自增后的id
//serviceImpl
int customerId = customerDao.insertDynamic(customer1);
System.out.println("id===================="+customer1.getId());
useGeneratedKeys:开启获取主键
keyProperty:那个字段是主键
<insert id="insertDynamic" parameterType="com.wftdlx.carApi.entity.Customer" useGeneratedKeys="true" keyProperty="id">
insert into customer
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
id,
</if>
<if test="activedate != null" >
activedate,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="id != null" >
#{id,jdbcType=BIGINT},
</if>
<if test="activedate != null" >
#{activedate,jdbcType=VARCHAR},
</if>
</trim>
</insert>
输出:id====================195466
mybatis 插入返回自增后的id的更多相关文章
- mybatis插入数据后返回自增主键ID详解
1.场景介绍: 开发过程中我们经常性的会用到许多的中间表,用于数据之间的对应和关联.这个时候我们关联最多的就是ID,我们在一张表中插入数据后级联增加到关联表中.我们熟知的mybatis在插入数据后 ...
- 关于mybatis用mysql时,插入返回自增主键的问题
公司决定新项目用mybatis,虽然这个以前学过但是一直没用过都忘得差不多了,而且项目比较紧,也没时间去系统点的学一学,只好很粗略的百度达到能用的程度就行了. 其中涉及到插入实体要求返回主键id的问题 ...
- Mybatis批量插入返回自增主键(转)
我们都知道Mybatis在插入单条数据的时候有两种方式返回自增主键: 1.对于支持生成自增主键的数据库:useGenerateKeys和keyProperty. 2.不支持生成自增主键的数据库:< ...
- mybatis插入的同时获取主键id
<insert id="insertAndReturnId" parameterType="com.qianlong.cms.entity.AppCmsRole&q ...
- mybaits返回自增主键ID
mybaits两种获取自增主键ID的方法:一种是使用useGeneratedKeys,第二种是selectKey方法获取. useGeneratedKeys <insert id="i ...
- Mybatis+Mysql插入数据库返回自增主键id值的三种方法
一.场景: 插入数据库的值需要立即得到返回的主键id进行下一步程序操作 二.解决方法: 第一种:使用通用mapper的插入方法 Mapper.insertSelective(record): 此方法: ...
- mybatis插入操作时,返回自增主键id
mapper.xml 代码 <insert id="insert" parameterType="com.Student" > <select ...
- mybatis插入实体到数据库后获取自增的主键
话不多说,直接说方法. 1.在insert语句中加入如下的代码. <insert id="insertSelective" parameterType="com.q ...
- MyBatis如何返回自增的ID
<insert id="insertTable" parameterType="com.infohold.city.map.model.CheckTemplateM ...
随机推荐
- ORA-01461的解决过程~~
转自:http://blog.itpub.net/7607759/viewspace-521189 近日生产库中的一个过程报出了ora-1461的错误,虽然错误实际处理起来非常简单,但解决过程中与ya ...
- expdp impdp 参数
With the Partitioning, OLAP, Data Mining and Real Application Testing options启动 "BEMIS".&q ...
- ORA-01940:无法删除当前已链接的用户(转)
(1)查看用户的连接状况 select username,sid,serial# from v$session ------------------------------------------ 如 ...
- python中的expandtabs、\t
expandtabs()将tab转换成空格,默认1个tab转成8个空格,\t制表符代表一个tab,我们也可以自定义转换成几个空格 举个例子: 1 a = "hello\tworld" ...
- Spring4 MVC HelloWord实例
一.创建Web项目 我用的eclipse,创建步骤:file=>New=>Other=>Web=>Dynamic Web project,按照操作创建一个完整的Web项目,下载 ...
- django之urlresolver
>>> from django.utils.regex_helper import normalize >>> bits=normalize(r'^static/( ...
- leetcode509
public class Solution { public int Fib(int N) { ) { ; } ) { ; } else { List<int> list = new Li ...
- 500G JAVA视频网盘分享 (JEECG开源社区)
500 G JAVA视频网盘分享(JEECG开源社区) [涵盖从java入门到深入架构,Linux.云计算.分布式.大数据Hadoop.ios.Android.互联网技术应有尽有] J ...
- java序列化问题
今天无意中看到了 redistemplet封装的类中,出现了序列化的字眼 ,了解下序列化的知识 1.什么是序列化 我们把变量从内存中变成可存储或传输的过程称之为序列化,(java中一般是用来保 ...
- Hbase数据读写流程
From: https://blog.csdn.net/wuxintdrh/article/details/69056188 写操作: Client写入,存入Memstore,Memstore满则Fl ...