要求: and 大於開始時間,
and 小於結束(位於開始時間和結束時間之間),
and (用戶類型爲0 or 或者類型爲2 )
按照創建時間排序
一些等值的個別條件
queryWrapper.and(wrapper -> wrapper.eq("user_type", "0")
.or().eq("user_type", 0 == customerState ? 1 : 2));
queryWrapper.and(wrapper -> wrapper.le("start_time", now))
.and(wrapper -> wrapper.ge("end_time", now));
queryWrapper.orderByDesc("create_time");
代碼如上,,最終sql如下圖!
SELECT
*
FROM
tbl_coupon
WHERE
display =?
AND deleted = 0
AND ( ( user_type = ? OR user_type = ?) )
AND ( ( start_time <= ?) )
AND ( ( end_time >= ?) )
ORDER BY
create_time DESC
LIMIT ?,?
and裏面多了個括號,也不知道怎麼搞的!嘿嘿,反正目前是實現了同時符合該業務需求!
各位大神,如有更佳方法,請指教!!!!!!!