MyBatis基础入门《十九》动态SQL(set,trim)

描述:

  1. 问题 :

    更新用户表数据时,若某个参数为null时,会导致更新错误

  2. 分析:

    正确结果:

      若某个参数为null,则不需要更新,保持数据库原值

  3. 如何处理

    > if

    > set

ClientMapper.xml 文件

ClientMapper.java

测试方法:

测试结果:

》》》 trim 

  >> 属性

    > prefix

    > suffix

    > prefixOverrides

    > suffixOverrides

  >> 更灵活的去除多余关键字

  >> 替代 where 和 set

ClientMapper.xml中的查询:

where标签代码 改造前:

where标签代码 改造后:

测试代码:

测试结果:

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

ClientMapper.xml中的更新:

 set改造前:

 

set改造后:

测试方法:

 

 测试结果:

如有问题,欢迎纠正!!!

如有转载,请标明源处:https://www.cnblogs.com/Charles-Yuan/p/9904013.html

MyBatis基础入门《十九》动态SQL(set,trim)的更多相关文章

  1. MyBatis基础入门《九》ResultMap自动匹配

    MyBatis基础入门<九>ResultMap自动匹配 描述: Mybatis执行select查询后,使用ResultMap接收查询的数据结果. 实体类:TblClient.java 接口 ...

  2. MyBatis基础入门《二十》动态SQL(foreach)

    MyBatis基础入门<二十>动态SQL(foreach) 1. 迭代一个集合,通常用于in条件 2. 属性 > item > index > collection : ...

  3. MyBatis基础入门《十八》动态SQL(if-where)

    MyBatis基础入门<十八>动态SQL(if-where) 描述: 代码是在<MyBatis基础入门<十七>动态SQL>基础上进行改造的,不再贴所有代码,仅贴改动 ...

  4. MyBatis基础入门《十七》动态SQL

    MyBatis基础入门<十七>动态SQL 描述: >> 完成多条件查询等逻辑实现 >> 用于实现动态SQL的元素主要有: > if > trim > ...

  5. MyBatis基础入门《十六》缓存

    MyBatis基础入门<十六>缓存 >> 一级缓存 >> 二级缓存 >> MyBatis的全局cache配置 >> 在Mapper XML文 ...

  6. MyBatis基础入门《十五》ResultMap子元素(collection)

    MyBatis基础入门<十五>ResultMap子元素(collection) 描述: 见<MyBatis基础入门<十四>ResultMap子元素(association ...

  7. MyBatis基础入门《十四》ResultMap子元素(association )

    MyBatis基础入门<十四>ResultMap子元素(association ) 1. id: >> 一般对应数据库中改行的主键ID,设置此项可以提高Mybatis的性能 2 ...

  8. MyBatis基础入门《十二》删除数据 - @Param参数

    MyBatis基础入门<十二>删除数据 - @Param参数 描述: 删除数据,这里使用了@Param这个注解,其实在代码中,不使用这个注解也可以的.只是为了学习这个@Param注解,为此 ...

  9. MyBatis基础入门《十 一》修改数据

    MyBatis基础入门<十 一>修改数据 实体类: 接口类: xml文件: 测试类: 测试结果: 数据库: 如有问题,欢迎纠正!!! 如有转载,请标明源处:https://www.cnbl ...

随机推荐

  1. SQL Server 查询数据库中被锁定的表

    在一次测试过程中,发现有些表一直被锁定,从网上搜集了下资料,可以使用一下语句查看数据库中那些表正被锁定: select request_session_id spid,OBJECT_NAME(reso ...

  2. js return false\e.preventDefault() 以及session

    @{ ViewBag.Title = "Test"; } <h2>Test</h2> 区别的介绍 <br/> 我们在平时的编码中javascri ...

  3. [skill][makefile] makefile 常用内容记录

    其实,makefile有点复杂. 文档看了又看,还是要经常翻,做个记录备忘 :) 1.  隐含命令 implicit rules 与 implicit rule 相对应的有 pattern rules ...

  4. LeetCode 908 Smallest Range I 解题报告

    题目要求 Given an array A of integers, for each integer A[i] we may choose any x with -K <= x <= K ...

  5. jmeter发送https请求

  6. appium入门(1)__ appium介绍

    摘自:http://www.testclass.net/appium/appium-base-summary/ 1.特点 appium 是一个自动化测试开源工具,支持 iOS 平台和 Android ...

  7. Python+Flash+NodeJS 接口自动化平台

    一.前端安装步骤# manager-web(1)下载项目 git clone https://github.com/t880216t/manager-web.git (2) 安装依赖 cnpm ins ...

  8. linux 查看文件目录大小

    du [-abcDhHklmsSx] [-L <符号连接>][-X <文件>][--block-size][--exclude=<目录或文件>] [--max-de ...

  9. 1-2-编译U-boot

    1-2-编译U-boot 1.su+enter进入超级用户模式. 2.cd /mnt/+两次Tab去到根目录,ls显示共享文件夹里的文件. 3.解压tar xvfj uboot_TQ210_1.3.4 ...

  10. SpringBoot-整合lombok

    添加lombok依赖 <dependency> <groupId>org.projectlombok</groupId> <artifactId>lom ...