mybatis动态sql中where标签的使用
2024-10-19 06:30:28
where标记的作用类似于动态sql中的set标记,他的作用主要是用来简化sql语句中where条件判断的书写的,如下所示:
<select id="selectByParams" parameterType="map" resultType="user">
select * from user
<where>
<if test="id != null ">id=#{id}</if>
<if test="name != null and name.length()>0" >and name=#{name}</if>
<if test="gender != null and gender.length()>0">and gender = #{gender}</if>
</where>
</select>
在上述SQL中加入ID的值为null的话,那么打印出来的SQL为:select * from user where name="xx" and gender="xx"
where 标记会自动将其后第一个条件的and或者是or给忽略掉
最新文章
- 解决Centos/Redhat,命令不存在
- python 实现简单排序
- JavaScript 总结几个提高性能知识点
- CSS3-Media Query 基础
- Leetcode#106 Construct Binary Tree from Inorder and Postorder Traversal
- JQuery DataTable插件
- 【动态规划】洛谷P1004方格取数
- 剑指Offer——网易笔试之不要二——欧式距离的典型应用
- saltstack主机管理项目:计主机管理项目命令分发器(三)
- 小兔的棋盘(hdu2067)
- git学习之时光穿梭机
- 零散的python知识点
- 2019.04.13 python基础
- (拼接SQL语句)mysql中date类型,datetime类型
- codeforces724G Xor-matic Number of the Graph
- Oracle 锁的等级
- 微信小程序echart 折线图legend不显示的问题
- 将 HPC 作业从本地计算机提交到部署在 Azure 中的 HPC Pack 群集
- ad各层
- new 运算符干了什么