单条件查询-动态条件查询(choose(when,otherwise))

  

  从多个条件中选择一个

  choose(when,otherwise) 选择,类似于java中的Switch语句(when 相当于 case  otherwise 相当于 default)

<!-- 单条件查询-动态查询 -->
<select id="selectByConditionSingle" resultMap="brandResultMap"> select * from tb_brand
where
<choose>
<when test="status != null">
status = #{status}
</when>
<when test="companyName != null and companyName != ''">
company_name like #{companyName}
</when>
<when test="brandName != null and brandName != ''">
brand_name like #{brand_name}
</when>
<otherwise>
1 = 1
</otherwise>
</choose>
</select>

  默认条件使用otherwise是不太方便的,可以使用上一节的 where标签即可

    <!-- 单条件查询-动态查询 -->
<select id="selectByConditionSingle" resultMap="brandResultMap"> select * from tb_brand
<where>
<choose>
<when test="status != null">
status = #{status}
</when>
<when test="companyName != null and companyName != ''">
company_name like #{companyName}
</when>
<when test="brandName != null and brandName != ''">
brand_name like #{brand_name}
</when>
</choose>
</where>
</select>

MyBatis——案例——查询-单条件查询-动态条件查询的更多相关文章

  1. mybatis+maven+父子多模块进行crud以及动态条件查询

    使用IDEA创建maven项目,File→New→Project→maven→Next→填写GroupId(例:com.zyl)和ArtifactId(mybatis-demo-parent)→Nex ...

  2. 【Oracle】曾经的Oracle学习笔记(4-7)多表联合查询,子查询,动态条件查询

    一.多表联合查询 二.子查询 三.动态条件查询 LESSON 4 Displaying Data from Multiple Tables------------------------------- ...

  3. Spring Data JPA,一种动态条件查询的写法

    我们在使用SpringData JPA框架时,进行条件查询,如果是固定条件的查询,我们可以使用符合框架规则的自定义方法以及@Query注解实现. 如果是查询条件是动态的,框架也提供了查询接口. Jpa ...

  4. spring-data-jpa动态条件查询

    //获取动态条件的集合List<Long> list = new ArrayList<Long>(); Long sysUserId = currentUser.getSysU ...

  5. 使用mybatis逆向工程Example类,(或者)or条件查询(Day_47)

    使用Example类,or条件查询 SetmealExample setmealExample=new SetmealExample(); setmealExample.or().andNameLik ...

  6. SEC6 - MySQL 查询语句--------------进阶2:条件查询

    # 进阶2:条件查询 /* 语法: select 查询列表 from 表名 where 筛选条件; 分类: 一.按照条件表达式筛选 条件运算符:> < = !=(等价于<>) ...

  7. Mybatis 使用注解和Provider类实现动态条件查询

    1.注解内拼写 Mybatis SQL 脚本 @Repository public interface CustomerFeedMapper extends BaseCrudMapper<Cus ...

  8. [C#] Linq 动态条件查询

    应用背景:以货品为例,在基础数据中配置货品的判断规则,要根据这个规则筛选出符合条件的集合. 创建货品类 public class Product { public string Name { get; ...

  9. SpringBoot中Example的动态条件查询

    一.无匹配器的情况: Person person = new Person(); person.setName("test"); Role role = new Role(); r ...

  10. Hibernate动态条件查询(Criteria Query)

    1.创建一个Criteria实例net.sf.hibernate.Criteria这个接口代表对一个特定的持久化类的查询.Session是用来制造Criteria实例的工厂. Criteria cri ...

随机推荐

  1. AT_agc017_b 题解

    洛谷链接&Atcoder 链接 本篇题解为此题较简单做法,请放心阅读. 题目简述 一共有 \(n\) 个格子,给定两个整数 \(A,B\) 分别位于第 \(1\) 和第 \(n\) 格,中间有 ...

  2. C#:进程之间传递数据

    一.思路 在Windows程序中,各个进程之间常常需要交换数据,进行数据通讯.常用的方法有 使用内存映射文件 通过共享内存DLL共享内存 使用SendMessage向另一进程发送WM_COPYDATA ...

  3. 计算机二级考试 C语言篇

    本篇仅适用于计算机二级考试C语言篇 首先介绍一下二级考试时间问题(以本人考试2022年为例): 一. 2022年全国计算机二级考试时间   2022年全国计算机考试举办4次,(3月.5月.9月.12月 ...

  4. ansible 部署hadoop

    规划 ansible 节点 ansible controller 镜像rhel 8.2 镜像ansible hadoop 集群 master slave1 slave2 镜像centos 1810 0 ...

  5. linux环境部署搭建流程

    linux环境部署搭建流程 1,ubuntu/centos系统安装 2,ip网络配置 3,路由和防火墙 4,时间同步服务器 5,ssh协议配置(Windows安装xshell/secureCRT) 6 ...

  6. 多智能体路径规划问题 —— Learn all about Multi-Agent Path Finding (MAPF)

    地址: http://mapf.info/index.php/Main/Publications 与其对应的实验室地址: https://www.movingai.com/

  7. 训练人形机器人时如何收集人类行为数据 —— 通过人来训练机器人(真人实际演示动作)or 仿真环境自动生成 —— 哪种方式更优、更可行呢

    特斯拉的老马,搞的optimus人形机器人就是通过人来训练机器人(真人实际演示动作),但是未来使用仿真环境自动生成数据是否可行呢,NVIDIA的老黄在2024 GTC上是大力推出自家的GROOT平台, ...

  8. Google的蛋白质结构预测项目代码(Demo)

    相关: Artificial Intelligence | 60 Minutes Full Episodes

  9. Python报错:performance hint: av/logging.pyx:232:5: the GIL to be acquired

    参考: https://stackoverflow.com/questions/77410272/problems-installing-python-av-in-windows-11 https:/ ...

  10. 分享某Python下的mpi教程 —— A Python Introduction to Parallel Programming with MPI 1.0.2 documentation ( 续 #2 )

    接前文: 分享某Python下的mpi教程 -- A Python Introduction to Parallel Programming with MPI 1.0.2 documentation ...