mybatisz中一個可以替代between..and 的技巧


用mybatis進行時間段篩選時,如果,查詢本日,本月的信息量,我們可以使用like concat()函數來替換between..and

<select id="queryMyStaffByShopId" parameterType="map" resultType="com.qlyd.shop.entity.out.SpreadUserOut">
select a.id staffid, b.avatar_url avatarUrl,b.nick_name name,(
select count(1) from shop_fans c
where c.promoter=a.uuid and a.shop_id=c.shop_id
<if test="createTime != null">
and c.create_time like concat ('%','${createTime}','%')
</if>
) totalCount
from user_staff a join user_info b
on a.uuid = b.unionid
where a.shop_id =#{shopId} and a.is_delete=0
<if test="name !=null">
and b.nick_name like concat ('%','${name}','%')
</if>
order by totalCount desc
</select>

like這個地方需要用${}來取值,不能使用#{}來取值


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM