mybatis中的if-else使用及if嵌套使用详解编程语言
2023-06-13 09:11:48 时间
案例一:if-else
在使用mybatis mapper 动态sql时,不免会出现if-else的使用,但是好像又没有这种语法,提供的是choose标签代替if-else
例如:
select * from t_stu t where choose when test="query == 0" and t.status = 1 /when otherwise and t.status NOT IN (9,5) /otherwise /choose and t.delete_status = 1 /where
也可以用多个if判断实现:
select * from t_stu t where if test="query == 0" and t.status = 1 /if if test="query != 0" and t.status NOT IN (9,5) /if and t.delete_status = 1 /where案例二:if嵌套
在实际编码过程中会有一些判断条件会一直重复使用,一直写在if标签中写的代码会特长,而且臃肿
select * from t_stu t where if test="query == 0 and type = 1" and t.type = we and t.delete = 1 /if if test="query == 0 and type = 2" and t.type = wq and t.delete = 1 /if if test="query == 0 and type = 3" and t.type = wr and t.delete = 1 /if /where
变现后:
select * from t_stu t where if test="query == 0" if test="type = 1" and t.type = we /if if test="type = 2" and t.type = wq /if if test="type = 3" and t.type = wr /if /if and t.delete = 1 /where
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/17659.html
cjava相关文章
- MyBatis-Plus 之逻辑删除
- 《深入理解mybatis原理》 MyBatis的一级缓存实现详解 及使用注意事项
- mybatis 分页查询避免两次查询同时返回总数和数据
- ssm框架过时了吗_mybatis分页插件
- 编写mybatis脱敏插件
- MyBatis-Plus 快速开始及详测 SpringBoot 集成Mybatis-Plus
- mybatis 分页原理_分页机结构原理
- MyBatis Plus 快速入门
- MyBatis-Plus联表查询(Mybatis-Plus-Join)
- MyBatis Plus 解决大数据量查询慢问题
- 理论:第五章:Spring和SpringMVC,MyBatis以及SpringBoot的注解分别有哪些?SpringMVC的工作原理,SpringBoot框架的
- mybatis基于注解的多对多关联操作
- Postgresql在mybatis中报错:操作符不存在:character varying == unknown的问题
- spring+spring mvc+mybatis详解编程语言
- MyBatis学习总结(八)——Mybatis3.x与Spring4.x整合详解编程语言
- MyBatis学习总结(七)——Mybatis缓存详解编程语言
- mybatis异常invalid comparison: java.util.Date and java.lang.String详解编程语言
- Mybatis if 判断等于一个字符串详解编程语言
- mybatis如何在控制台或者tomcat日志中打印出执行的sql语句详解编程语言
- SpringBoot连接MySql数据库集成Mybatis详解编程语言
- mybatis if标签比较字符串详解编程语言
- Spring Boot(六):如何使用mybatis详解编程语言
- mybatis 使用接口增删改查和两表一对一关联查询详解编程语言
- mybatis与hibernate区别详解编程语言
- mybatis中查询结果为空时不同返回类型对应返回值详解编程语言
- Mybatis——mapper代理详解编程语言