mybatis update set 多个字段
<update id="updateCustomer" parameterType="com.entrym.domain.Customer">
UPDATE customer set
<if test="name!=null">name=#{name,jdbcType=VARCHAR},</if>
<if test="role!=null">role=#{role,jdbcType=VARCHAR},</if>
<if test="userId != null">user_id = #{userId,jdbcType=INTEGER},</if>
<if test="qq != null">qq = #{qq,jdbcType=VARCHAR},</if>
<if test="mobile != null">mobile = #{mobile,jdbcType=VARCHAR}</if>
WHERE id =#{id,jdbcType=BIGINT}
如果上面的mobile字段为null,执行下面的SQL语句
UPDATE customer set name=?,role=?,userId=?,qq=?, where id=?
where 前面有逗号“,”就会报错
使用trim可以删掉最后字段的逗号“,”
set已被包含在trim中,所以不用重复写了:
<update id="updateCustomer" parameterType="com.entrym.domain.Customer">
UPDATE customer
<trim prefix="set" suffixOverrides=",">
<if test="claimTime!=null">claim_time=#{claimTime,jdbcType=VARCHAR},</if>
<if test="claimState!=null">claim_state=#{claimState,jdbcType=INTEGER},</if>
<if test="name!=null">name=#{name,jdbcType=VARCHAR},</if>
<if test="role!=null">role=#{role,jdbcType=VARCHAR},</if>
<if test="platformAccount!=null">platform_account=#{platformAccount,jdbcType=VARCHAR},</if>
<if test="collaborateTime!=null">collaborate_time=#{collaborateTime,jdbcType=VARCHAR},</if>
<if test="collaborateState!=null">collaborate_state=#{collaborateState,jdbcType=INTEGER},</if>
<if test="userId != null">user_id = #{userId,jdbcType=INTEGER},</if>
<if test="qq != null">qq = #{qq,jdbcType=VARCHAR},</if>
<if test="mobile != null">mobile = #{mobile,jdbcType=VARCHAR}</if>
</trim>
WHERE id =#{id,jdbcType=BIGINT}
</update>
转义字符:
< 小于号 <
> 大于号 >
& 和 &
' 单引号 ’
" 双引号 "
-------------------------------------充足的睡眠、均衡饮食和适当的运动是健康生活的三个鼎足----------------------------------------
mybatis update set 多个字段的更多相关文章
- Mybatis Update statement Date null
Mybatis Update statement Date null 只要在Model里把字段置为java的null即可.
- update更新两个字段
update更新两个字段时的sql语句: update tj_record set is_recycle_reprint_guide='1' , recycle__guide_date=now() w ...
- 【转】MyBatis学习总结(四)——解决字段名与实体类属性名不相同的冲突
[转]MyBatis学习总结(四)——解决字段名与实体类属性名不相同的冲突 在平时的开发中,我们表中的字段名和表对应实体类的属性名称不一定都是完全相同的,下面来演示一下这种情况下的如何解决字段名与实体 ...
- mybatis操作动态表+动态字段+存储过程
存储过程 statementType="CALLABLE" <!-- 计算金额存储过程--> <update id="getCalcDistributo ...
- 修改mybatis plus Generator模板生成字段注释枚举常量
修改mybatis plus Generator模板生成字段注释枚举常量 本文基于最新的mybatis-plus 3.0.1版本源码修改,如果使用其它版本,处理方式也类似,主要是生成Entity的Fr ...
- 2.mybatis 的列名与数据库字段不对应
mybatis 的列名与数据库字段不对应 1.别名 映射文件 : BlogMapper.xml <mapper namespace="com.xms.mybatis.mapper.Bl ...
- 使用SQL中的update更新多个字段值
使用SQL中的update更新多个字段值,set后面的条件要用逗号不能用and set后面的多个条件之间没有关联也不可以有关联,所以就不能用and了:where 条件后面 可以为and 如: upda ...
- 【mybatis】 mybatis在mysql 更新update 操作 更新时间字段按照年月日时分秒格式 更新为当前时间
示例代码如下: update goods_msg SET create_date = DATE_FORMAT(NOW(),'%Y-%m-%d %H:%m:%s') WHERE uid = '6183b ...
- Mybatis框架学习总结-解决字段名与实体类属性名不相同的冲突
在平时的开发中,我们表中的字段名和表对应实体类的属性名称不一定是完全相同的. 1.准备演示需要使用的表和数据 CREATE TABLE orders( order_id INT PRIMARY KEY ...
随机推荐
- Android Studio的HAXM不支持虚拟机
因为我的计算机是服务器,不支持虚拟机,所以报这个错了. 解决方式是直接连接物理手机,打开USB调试,安装驱动,运行项目即可.
- angular 自定义服务封装自定义http请求
在angular中将http请求,放置在一起封装成服务,可减少代码重复,方便使用 var ngpohttprest = angular.module('ngpohttprest', []); ngpo ...
- 「HNOI2016」大数
题目描述 给定一个质数\(p\)和一个数字序列,每次询问一段区间\([l,r]\), 求出该序列区间\([l,r]\)内的所有子串,满足该子串所形成的数是\(p\)的倍数(样例的解释也挺直观的) 基本 ...
- Centos7 iptables firewalld防火墙与selinux配置
一.iptables防火墙 1.基本操作 # 查看防火墙状态 service iptables status # 停止防火墙 service iptables stop # 启动防火墙 service ...
- hdu 1086 You can Solve a Geometry Problem too 求n条直线交点的个数
You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/3 ...
- mybatis动态参数查询
参考:https://blog.csdn.net/zbw18297786698/article/details/53727594
- ROS学习笔记10-写一个简单的订阅者和发布者(C++版本)
本文档来源于:http://wiki.ros.org/ROS/Tutorials/WritingPublisherSubscriber%28c%2B%2B%29 写发布者节点如前所述,节点是连接到RO ...
- video-editing
1. 视频编辑 2. 视频编辑软件列表 3. 视频编辑软件比较 4. 视频转换 1. 视频编辑 https://zh.wikipedia.org/wiki/视频编辑 2. 视频编辑软件列表 https ...
- [Verilog] indexed part-select +:
That syntax is called an indexed part-select. The first term is the bit offset and the second term ...
- 096、Java中String类之手工入对象池操作
01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...