要求: 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里面多了个括号,也不知道怎么搞的!嘿嘿,反正目前是实现了同时符合该业务需求!
各位大神,如有更佳方法,请指教!!!!!!!