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的更多相关文章

  1. MyBatis updateByExample和updateByExampleSelective的区别

    大家都用过mybatis generator来生产数据库的xml文件,但是关于updateByExample和updateByExampleSelective的区别我之前一直分不太清楚. 如果分不清楚 ...

  2. mybatis中的updateByExampleSelective方法怎么使用

    mybatis中的updateByExampleSelective方法怎么使用.sendDetailMapper.updateByExampleSelective(sendDetail, m);参数m ...

  3. mybatis中的mapper接口文件以及example类的实例函数以及详解

    ##Example example = new ##Example(); example.setOrderByClause("字段名 ASC"); //升序排列,desc为降序排列 ...

  4. mybatis逆向工程之生成文件解释

    一.mapper接口中的方法解析 mapper接口中的函数及方法 方法 功能说明 int countByExample(UserExample example) thorws SQLException ...

  5. MyBatis的Mapper接口以及Example的实例函数及详解

    来源:https://blog.csdn.net/biandous/article/details/65630783 一.mapper接口中的方法解析 mapper接口中的函数及方法 方法 功能说明 ...

  6. mybatis中的mapper接口文件以及selectByExample类的实例函数详解

    记录分为两个部分,第一部分主要关注selectByExample类的实例函数的实现:第二部分讨论Mybatis框架下基本的实例函数. (一)selectByExample类的实例函数的实现 当你启动项 ...

  7. MyBatis 通用Mapper接口 Example的实例

    一.mapper接口中的方法解析 mapper接口中的函数及方法 方法 功能说明 int countByExample(UserExample example) thorws SQLException ...

  8. MyBatis逆向工程中的Mapper接口以及Example的实例函数及详解

    一.mapper接口中的方法解析 mapper接口中的函数及方法 方法 功能说明 int countByExample(UserExample example) thorws SQLException ...

  9. 使用mybatis动态where字句方法

    上篇文章介绍了如何使用mybatis-generator生成实体类.Mapper接口代码,其中生成的Mapper接口代码是不带ByExample方法的.本篇文章将介绍如何使用mybatis-gener ...

随机推荐

  1. 用JSON.stringify去实现深拷贝的弊端

    无法处理function啦还有RegExp啦,还有无法处理循环引用对象(这个我还没有test) 就前两点的话 var a={ a:, b:new RegExp('test'), c:function( ...

  2. uni-app 无痛刷新 token 方法

    为了给用户一个流畅的体验, token 过期后需要重新请求新的 token 替换过期的 token 前端在请求接口时,和后端定义好了,如果状态码为 401 ,则表明 token 过期,需要前端请求新的 ...

  3. 简单几招提速 Kotlin Kapt编译

    https://droidyue.com/blog/2019/08/18/faster-kapt/?hmsr=toutiao.io&utm_medium=toutiao.io&utm_ ...

  4. App过大

    最近开发中遇到一个报错信息 如下 Error:Cannot fit requested classes in a single dex file.Try supplying a main-dex li ...

  5. (原+修改)ubuntu上离线安装pytorch

    转载请注明出处: https://www.cnblogs.com/darkknightzh/p/12000809.html 参考网址: https://blog.csdn.net/qq_4193655 ...

  6. Maven编译过程中出现的问题

    在用Jenkins编译Gitlab上代码过程中,实际使用的是Maven服务器上的打包命令,以下为打包过程中出现的问题及解决方案 问题一:Maven无法编译Snapshot版本代码 答:登录至maven ...

  7. Linux上搭建SVN服务

    环境:centos7 一.搭建svn服务 1. 安装svn yum -y install subversion 2. 创建一个目录作为svn服务的地址(svn://192.168.0.2:3690 访 ...

  8. nginx.conf 下日志host.access.log 说明

    位置usr/local/nginx/conf/nginx.conf $server_port 请求端口 $remote_addr 局域网代理IP:如果没同意任何代理的话$remote_addr 就是真 ...

  9. mac运行模拟器simulator突然很慢

    一直都正常,突然变慢,而且慢的离谱. 上网查了下,这里记录下,或许问题不仅限于此. simulator->Debug->Slow Animations. 这个Slow Animations ...

  10. AMD Ryzen一代、二代CPU一览表

    Ryzen一代(14纳米).二代(12纳米)CPU一览表 http://img30.360buyimg.com/sku/jfs/t1/1134/23/12713/382299/5bd910f9E63b ...