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);

最新文章

  1. HTML5魔法堂:全面理解Drag &amp; Drop API
  2. linux命令格式及基础命令(一)
  3. FreeMarker操作符
  4. DOM概述
  5. FFRPC应用之Client/Server
  6. poj 2186 有向图强连通分量
  7. 配置tomcat时踩过的坑
  8. RH442之Tuned优化方案
  9. java_设计模式_适配器模式_Adapter Pattern(2016-08-09)
  10. Hive 创建和生成Rcfile 和SequenceFile格式的表
  11. 龙杰ACR122S NFC读卡器
  12. 开源项目之Android Afinal框架
  13. Gimp制作圆角透明图片
  14. IM 之 融云
  15. 【BZOJ2729】【HNOI2012】排队(组合数学)
  16. python 报错 TabError: inconsistent use of tabs and spaces in indentation
  17. JS 验证输入框输入 只允许输入正实数(正整数,正小数),其他情况下不能输入 oninput事件
  18. c/c++ 大于等于 大于 时间效率比较
  19. Django框架(三)
  20. Apache Commons Digester 三(规则注解)

热门文章

  1. 用Python爬E站本
  2. Python模块File文件操作
  3. 操作系统与进程.md
  4. 海思3519A 移植ffmpeg
  5. 配置以https访问网站
  6. Alipay 支付宝SDK PHP Fatal error: Class &#39;LtObjectUtil&#39; not found in。
  7. java lambda表达式检查list集合是否存在某个值
  8. linux socket编程系统调用栈
  9. android 发布时去除Log
  10. JDOJ 1140: 完数