mybatis中if test 可以使用== != null '' and or 和括号()

本文介绍了一个使用MyBatis Plus进行复杂SQL查询构造的例子,包括条件判断和日期筛选等操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<if test="pd.flag==1 or ((pd.flag==2 or pd.flag==3) and (pd.sfyj==2 or pd.sfyj==3)) or pd.flag==3">
    union all
  </if>

 

 <if test="pd.ssny != null and pd.ssny != ''">
     and z.sjssny >= '${pd.ssny}'
     </if>

转载于:https://www.cnblogs.com/shenzhichipingguo/p/8876357.html

SELECT DISTINCT 'video' AS type, smv.video_id AS id, smv.video_title AS title, NULL AS channelId, '' AS channelType, '' AS channelName, '' AS channelCode, '' AS shortLink, '' AS longLink, smv.file_id AS fileId, smv.create_time FROM sys_media_video smv LEFT JOIN sys_file_info sfi ON smv.cut_file_id = sfi.file_id LEFT JOIN sys_label sl ON smv.label_id = sl.id LEFT JOIN sys_tag st ON smv.label_id = st.id <where> smv.del_flag = '0' and smv.push_home_page = '1' <if test="title != null and title != ''">AND smv.video_title like concat('%', #{title}, '%')</if> <if test="searchValue != null and searchValue != ''">and smv.video_title like concat('%', #{searchValue},'%')</if> <if test="channelType != null and channelType != ''">AND 1=2</if> <if test="channelName != null and channelName != ''">AND 1=2</if> <if test="channelCode != null and channelCode != ''">AND 1=2</if> <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 --> AND smv.create_time >= #{params.beginTime} </if> <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 --> AND smv.create_time <= #{params.endTime} </if> <if test="labelId != null and labelId != ''">and smv.label_id = #{labelId}</if> <if test="labelIds != null and labelIds.length > 0"> and (smv.label_id in <foreach collection="labelIds" item="labelId" open="(" separator="," close=")"> #{labelId} </foreach> ) </if> <if test="tagId != null and tagId != ''">and FIND_IN_SET( #{tagId} , smv.tag_id )</if> <if test="tagIds != null and tagIds.length > 0"> and <foreach collection="tagIds" item="tagId" open="(" separator="," close=")"> FIND_IN_SET( #{tagId} , smv.tag_id ) or </foreach> </if> </where> 修改
04-01
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值