mybatis:updatebyexample与updateByExampleSelective
MyBatis,通常逆向工程工具生成接口和xml映射文件用于简单的单表操作。
有两个方法: updateByExample 和 updateByExampleSelective ,作用是对数据库进行更新操作。(insert和insertSelective也一球样!)
注意:1,区别在于后者比前者多了动态标签<if test="xxx != null">的判断,有空值,不进行插入操作。
2,updateByExampleSelective可以不按主键更新,条件中可以不包含主键;updateByExample条件中必须包含主键。
updateByExample:
<update id="updateByExample" parameterType="map" >
update tb_item
set id = #{record.id,jdbcType=BIGINT},
title = #{record.title,jdbcType=VARCHAR},
sell_point = #{record.sellPoint,jdbcType=VARCHAR},
price = #{record.price,jdbcType=BIGINT},
num = #{record.num,jdbcType=INTEGER},
barcode = #{record.barcode,jdbcType=VARCHAR},
image = #{record.image,jdbcType=VARCHAR},
cid = #{record.cid,jdbcType=BIGINT},
status = #{record.status,jdbcType=TINYINT},
created = #{record.created,jdbcType=TIMESTAMP},
updated = #{record.updated,jdbcType=TIMESTAMP}
<if test="_parameter != null" >
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
updateByExampleSelective:
<update id="updateByExampleSelective" parameterType="map" >
update tb_item
<set >
<if test="record.id != null" >
id = #{record.id,jdbcType=BIGINT},
</if>
<if test="record.title != null" >
title = #{record.title,jdbcType=VARCHAR},
</if>
<if test="record.sellPoint != null" >
sell_point = #{record.sellPoint,jdbcType=VARCHAR},
</if>
<if test="record.price != null" >
price = #{record.price,jdbcType=BIGINT},
</if>
<if test="record.num != null" >
num = #{record.num,jdbcType=INTEGER},
</if>
<if test="record.barcode != null" >
barcode = #{record.barcode,jdbcType=VARCHAR},
</if>
<if test="record.image != null" >
image = #{record.image,jdbcType=VARCHAR},
</if>
<if test="record.cid != null" >
cid = #{record.cid,jdbcType=BIGINT},
</if>
<if test="record.status != null" >
status = #{record.status,jdbcType=TINYINT},
</if>
<if test="record.created != null" >
created = #{record.created,jdbcType=TIMESTAMP},
</if>
<if test="record.updated != null" >
updated = #{record.updated,jdbcType=TIMESTAMP},
</if>
</set>
<if test="_parameter != null" >
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
UpdateByExampleSelectivce使用:
ProLogExample example = new ProLogExample();
example.createCriteria().andNameEqualTo(xiaoming.getName());
proLogMapper.updateByExampleSelective(xiaoming, example);
mybatis:updatebyexample与updateByExampleSelective的更多相关文章
- MyBatis updateByExample和updateByExampleSelective的区别
大家都用过mybatis generator来生产数据库的xml文件,但是关于updateByExample和updateByExampleSelective的区别我之前一直分不太清楚. 如果分不清楚 ...
- mybatis中的updateByExampleSelective方法怎么使用
mybatis中的updateByExampleSelective方法怎么使用.sendDetailMapper.updateByExampleSelective(sendDetail, m);参数m ...
- mybatis中的mapper接口文件以及example类的实例函数以及详解
##Example example = new ##Example(); example.setOrderByClause("字段名 ASC"); //升序排列,desc为降序排列 ...
- mybatis逆向工程之生成文件解释
一.mapper接口中的方法解析 mapper接口中的函数及方法 方法 功能说明 int countByExample(UserExample example) thorws SQLException ...
- MyBatis的Mapper接口以及Example的实例函数及详解
来源:https://blog.csdn.net/biandous/article/details/65630783 一.mapper接口中的方法解析 mapper接口中的函数及方法 方法 功能说明 ...
- mybatis中的mapper接口文件以及selectByExample类的实例函数详解
记录分为两个部分,第一部分主要关注selectByExample类的实例函数的实现:第二部分讨论Mybatis框架下基本的实例函数. (一)selectByExample类的实例函数的实现 当你启动项 ...
- MyBatis 通用Mapper接口 Example的实例
一.mapper接口中的方法解析 mapper接口中的函数及方法 方法 功能说明 int countByExample(UserExample example) thorws SQLException ...
- MyBatis逆向工程中的Mapper接口以及Example的实例函数及详解
一.mapper接口中的方法解析 mapper接口中的函数及方法 方法 功能说明 int countByExample(UserExample example) thorws SQLException ...
- 使用mybatis动态where字句方法
上篇文章介绍了如何使用mybatis-generator生成实体类.Mapper接口代码,其中生成的Mapper接口代码是不带ByExample方法的.本篇文章将介绍如何使用mybatis-gener ...
随机推荐
- 《Real World Haskell》内容脉络整理
p.s. 其实就是28–(6入门[1~4,6])-(10暂不用[17,20~28])=13网页啊! 1~ 6 章: 语法入门 (类型,函数,表达式语法糖,typeclass) 7~13章: 熟练/ ...
- VirtualBox安装Ubuntu-18.04-Server笔记
准备 安装'Windows Terminal' 安装WSL 安装VirtualBox 安装 虚拟磁盘映像文件选择创建在SSD(如果有) 选择openssh,公钥从GitHub获取,前提是GitHub已 ...
- Android Xutils3 完全解析
1.先来认识一下xUtils3 1)xUtils3简介 xUtils是基于Afinal开发的目前功能比较完善的一个Android开源框架,最近又发布了xUtil3.0,在增加新功能的同时又提高了框架的 ...
- contab路径问题(脚本调用另一个文件)
问题描述 当在定时任务里,要执行一个脚本A,然后A脚本需要调用另一个文件B,此时定时任务执行不成功,会报错找不到文件 解决办法 先cd到放执行脚本的路径,这样就在定时任务的脚本里可以调用相对路径下 ...
- Odoo中的字段显示方式和行为控制
在odoo的视图中,字段都是通过widget来控制显示效果和行为的. 一般情况下,不同类型的字段odoo会使用默认的widget来显示和控制它的行为. options以一种JSON对象的形 ...
- django-配置404页面
setting.py文件配置 # SECURITY WARNING: don't run with debug turned on in production! DEBUG = False ALLOW ...
- 《Pro Continuous Delivery With Jenkins 2.0》随书笔记
今天同时看完<Pro Continuous Delivery With Jenkins 2.0>, 这书与工作关系很大,但也是快速翻翻. 本书着重点jenkins高可用环境搭建,与gith ...
- MMORPG服务器场景中的aoi算法思考
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/lwtbn1/article/details/37961695 最近在做一个移动平台上的MMORPG项 ...
- 第04节-BLE协议抓包演示
在上几篇博客中,形象的讲解了BLE各个层的作用,各个层的数据结构.本篇博客将研究BLE协议抓包.在实际开发中,有一个中央设备(central)和一个外设(Peripheral).所谓中央设备就是指它可 ...
- 《浅谈我眼中的express、koa和koa2》好文留存+笔记
原文 :三英战豪强,思绪走四方.浅谈我眼中的express.koa和koa2 一.回调大坑怎么解决呢? 1.es5可以利用一下第三方库,例如 async 库, 2.或者单纯使用 connect中间件 ...