当前位置:   article > 正文

MyBatis/MyBatis-Plus之AND和OR合用查詢_mybatisplus or查询

mybatisplus or查询
  1. /*
  2. * 未开始 start_time>= 当前时间
  3. * 进行中 start_time<= 当前时间 AND end_time>= 当前时间
  4. */
  5. LocalDateTime now = LocalDateTime.now();
  6. QueryWrapper<Activity> activityQueryWrapper = new QueryWrapper<>();
  7. activityQueryWrapper.and(
  8. queryWrapper -> queryWrapper.ge("start_time", now)
  9. .or(
  10. qw -> qw.le("start_time", now).ge("end_time", now)
  11. )
  12. );
  13. activityQueryWrapper.eq("del_flag", 0);
  1. SELECT
  2. id,
  3. title,
  4. start_time,
  5. end_time,
  6. del_flag
  7. FROM
  8. `activity`
  9. WHERE (
  10. start_time >= '2022-08-30T15:04:04.452'
  11. OR (
  12. start_time <= '2022-08-30T15:04:04.452'
  13. AND end_time >= '2022-08-30T15:04:04.452'
  14. )
  15. )
  16. AND del_flag = 0 ;

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/158329
推荐阅读
相关标签
  

闽ICP备14008679号