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. Common Lisp : Symbol到底是什么

    主要参考: <Emacs之魂>(四) 包:

  2. delphi实现窗体闪烁功能

    delphi实现窗体闪烁功能 以前做窗口闪动时都没有考虑到让任务栏上的按钮闪动的问题, 现在一个客户需要任务栏按钮闪动,发现以前使用的flashwindow不能达到要求了, 查找了一下,找到flash ...

  3. CSS泣鬼神

    博主网站 一.CSS介绍和语法 CSS(Cascading Style Sheet,层叠样式表)定义如何显示HTML元素. 每个CSS样式由两个组成部分:选择器和声明.声明又包括属性和属性值.每个声明 ...

  4. doucment的获取节点的信息

    document.activeElement 返回当前获取焦点元素 document.addEventListener() 向文档添加句柄 document.adoptNode(node) 从另外一个 ...

  5. 【转】面试题:实现一个队列,这个队列除了有EnQueue, DeQueue操作,还有一个Max操作,三个操作复杂度都是O(1)

    1.每次  新元素进栈的时候,栈里面的元素需要排序 2.让最小的或者最大的元素位于栈顶,这样就可以在O(1)时间内获得最小或者最大的值了, ------ 3.上面的想法  不能保证,进栈(进了队列)之 ...

  6. 一个很简单的SpringCloud项目,集成Feign、Hystrix

    Feign的功能:这是个消费者,根据服务注册在Eureka的ID去找到该服务,并调用接口Hystrix的功能:熔断器,假如A服务需要调用B服务的/cities接口获取数据,那就在A服务的control ...

  7. Linux shell简单创建用户脚本

    前面介绍简单的shell编写规则. 现在开始编写一个简单的shell脚本. Linux shell介绍 编写shell脚本    1.创建脚本文件    2.根据需求,编写脚本    3.测试执行脚本 ...

  8. XGBoost使用教程(与sklearn一起使用)二

    一.导入必要的工具包# 运行 xgboost安装包中的示例程序from xgboost import XGBClassifier # 加载LibSVM格式数据模块from sklearn.datase ...

  9. POJ 3694Network(Tarjan边双联通分量 + 缩点 + LCA并查集维护)

    [题意]: 有N个结点M条边的图,有Q次操作,每次操作在点x, y之间加一条边,加完E(x, y)后还有几个桥(割边),每次操作会累积,影响下一次操作. [思路]: 先用Tarjan求出一开始总的桥的 ...

  10. 让Discuz! X3.2 SEO标题里的“-”支持空格

    打开Discuz!根目录下source\class\helper\helper_seo.php文件找到如下代码: public static function strreplace_strip_spl ...