<select id="countDTO" resultType="java.lang.Integer"
parameterType="com.DTO">
select count(id)//主键id
from
${tableName}//你的表名
where is_deleted = 0
//id集合查询传入product_id 的集合productIds
<if test="productIds != null and productIds.size() > 0 ">//集合判空
and product_id in
<foreach collection="productIds" item="code" open="(" close=")" separator=",">
#{code}
</foreach>
</if>
//模糊匹配specialName
<if test="specialName != null and specialName != '' ">
and special_name like concat('%',replace(#{specialName,jdbcType=VARCHAR},'%','/%'),'%') escape '/'
</if>
//recordDateStart 大于等于开始时间小于等于结束时间
<if test="recordDateStart != null">
and record_date_start <![CDATA[>=]]> #{recordDateStart}
</if>
<if test="recordDateEnd != null">
and record_date_end <![CDATA[<=]]> #{recordDateEnd}
</if>
</select>
MyBatis查询 传入条件 模糊匹配 日期范围 id集合
最新推荐文章于 2024-09-13 09:46:55 发布
本文通过一个具体的MyBatis动态SQL示例,详细解析了如何使用if标签进行条件判断,foreach标签进行集合遍历,以及如何实现模糊查询和时间范围查询。通过这个例子,读者可以了解到MyBatis动态SQL的强大功能。
479

被折叠的 条评论
为什么被折叠?



