Mybatis中updateByPrimaryKeySelective和updateByPrimaryKey区别
- int updateByPrimaryKeySelective(TbItem record);
- int updateByPrimaryKey(TbItem record);
上面的是逆转工程生成的Mapper接口
对应的xml为
<update id="updateByPrimaryKeySelective" parameterType="com.taotao.pojo.TbItem">
update tb_item
<set>
<if test="title != null">
title = #{title,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKey" parameterType="com.taotao.pojo.TbItem">
update tb_item
set title = #{title,jdbcType=VARCHAR},
where id = #{id,jdbcType=BIGINT}
</update>
updateByPrimaryKeySelective会对字段进行判断再更新(如果为Null就忽略更新),如果你只想更新某一字段,可以用这个方法。
updateByPrimaryKey对你注入的字段全部更新
Mybatis中updateByPrimaryKeySelective和updateByPrimaryKey区别的更多相关文章
- mybatis中updateByPrimaryKeySelective
mybatis中updateByPrimaryKeySelective等选择性操作在判断时对于VARCHAR类型需要同时判断非空和非空串 <if test="description ! ...
- Mybatis中的#与$的区别
一.对比场景 场景:数据库分表时,需要将分表的表序号传入的sql中. SpringBoot中使用注解如下: @Insert("insert into collect_#{tblNum}(id ...
- 【mybatis】mybatis中 的# 和 $的区别
mybatis中 的# 和 $的区别 参考地址:https://www.cnblogs.com/sxdcgaq8080/p/10869144.html
- mybatis中的#和$的区别 以及 防止sql注入
声明:这是转载的. mybatis中的#和$的区别 1. #将传入的数据都当成一个字符串,会对自动传入的数据加一个双引号.如:order by #user_id#,如果传入的值是111,那么解析成sq ...
- [转]MyBatis中resultType与resultMap区别
MyBatis中关于resultType和resultMap的具体区别如下: MyBatis中在查询进行select映射的时候,返回类型可以用resultType,也可以用resultMap.resu ...
- 【mybatis】从一个错误,看mybatis中的#和$的区别
事情的发展是这样的: 因为一个需求,需要在java中拼接出一个完整的sql语句,然后将整条sql语句传递给mybatis执行. mapper.java是这样的: int insertMaster(Wo ...
- Mybatis中的#{}和${}的区别?
1,首先Mybatis中的#{}与${}到底有什么区别? #{}:表示一个占位符号,通过#{}可以实现preparedStatement向占位符中设置值,自动进行java类型和jdbc类型转换,#{} ...
- 浅析mybatis中${}和#{}取值区别
mybatis作为一个轻量级的ORM框架,应用广泛,其上手使用也比较简单:一个成熟的框架,必然有精巧的设计,值得学习. 在使用mybatis框架时,在sql语句中获取传入的参数有如下两种方式: ${p ...
- Mybatis中resultMap与resultType区别
MyBatis中在查询进行select映射的时候,返回类型可以用resultType,也可以用resultMap,resultType是直接表示返回类型的,而resultMap则是对外部ResultM ...
随机推荐
- Python函数(1)
一.Python函数介绍 函数时组织好的,可重复的,用来实现单一,或相关联功能的代码段. 函数的使用原则时先定义,后调用:事先准备工具的过程即函数的定义,遇到应用场景拿来当工具用即函数的调用. 函数的 ...
- arcgis Flex QueryTask
<esri:Map id="myMap" creationComplete="useMapServicePermaLink()" load="u ...
- 【起航计划 016】2015 起航计划 Android APIDemo的魔鬼步伐 15 App->Activity->Wallpaper 系统壁纸作为当前Activity的背景
Wallpaper介绍一个Activity如何通过Style把系统Wallpaper作为当前Activity的背景. 这是WallpaperActivity在AndroidManifest.xml中的 ...
- Ubuntu 14.04 软件源服务器集合
http://wiki.ubuntu.com.cn/Template:14.04source 服务器列表 可将 http://cn.archive.ubuntu.com/ubuntu/ 替换为下列任意 ...
- JavaScript 关闭浏览器窗口
<input type="button" name="m" value="关闭窗口" onclick="window.clo ...
- May 05th 2017 Week 18th Friday
No matter what have happened today, the sun will just rise in the morning of tomorrow. 无论今天发生了什么,明天早 ...
- TCP的可靠连接是如何产生的?
http://bbs.csdn.net/topics/190011812 看过TCP/IP的源代码没?tcp中所谓的连接只是在tcp的tcb中存储了对端的地址信息,并且记录连接的状态,通过重发之类的来 ...
- LA 2965 中途相遇法
题目链接:https://vjudge.net/problem/UVALive-2965 题意: 有很多字符串(24),选出一些字符串,要求这些字符串的字母都是偶数次: 分析: 暴力2^24也很大了, ...
- ORA-00392: log 4 of thread 2 is being cleared, operation not allowed
alter database open resetlogs或者 alter database open resetlogs upgrade报错:ORA-00392 在rman restore 还原数 ...
- json 序列化和反序列化的3个方法
https://www.cnblogs.com/caofangsheng/p/5687994.html