本文介绍: Mybatis 常用条件语句

大于小于

方法1: > 大于 , < 小于

<if test="startTime != null ">
    and a.create_time &gt;= #{startTime}
</if>
<if test="endTime != null ">
    and a.create_time &lt;= #{endTime}
</if>

方法2(建议写这个): 

在idea输入CD应该就自动出来了

if 条件判断 

<if test="deviceId != null and deviceId != '' ">
    and a.device_id = #{deviceId}
</if>

for循环

<if test="partsIdList != null ">
    and b.id in
    <foreach item="item" index="index" collection="partsIdList" open="(" separator="," close=")">
        #{item}
    </foreach>
</if>

LIKE 模糊搜索

<if test='phone!=null and phone!=""' >
            where b.phone LIKE concat('%',#{phone},'%')
 </if>
<if test="dataRole == 0">
    AND pn.org_code LIKE CONCAT(#{orgCode},'%')
</if>

case when

choose选择语句

满足when条件走when,否则执行otherwise 

<choose>
    <when test="dto!=null and dto.dataRole='0'">
        AND i.org_code like concat(#{dto.orgCode},'%')
    </when>
    <otherwise>
        AND i.org_code = #{dto.orgCode}
    </otherwise>
</choose>

 

——————————————与正文内容无关————————————
如果觉的文章写对各位读者老爷们有帮助的话,麻烦点赞加关注呗!小弟在这拜谢了!
如果您觉得我的文章在某些地方写的不尽人意或者写的不对,从而让你对你人生观产生颠覆(概不负责),需要斧正,麻烦在评论区不吝赐教,作者看到后会根据您的提示查阅文章进行修改,还这世间一个公理一片蓝天

原文地址:https://blog.csdn.net/weixin_43895362/article/details/135587273

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。

如若转载,请注明出处:http://www.7code.cn/show_57558.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除!

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注