当前位置:   article > 正文

Mybatis-Plus的 QueryWrapper中 AND 和OR条件运算逻辑_querywrapper.and

querywrapper.and

SQL中 OR条件左右只要有一个成立,就可以返回true结果,所以在和and使用得时候 ,OR必须要加上括号来使用。

  1. queryWrapper.and(Wrapper -> Wrapper.like("first_name", "nana").or().like("last_name ","nana"));
  2. queryWrapper.ge("actor_id",10);
  3. // 等同于 WHERE actor_id > 10 AND (first_name LIKE '%A%' OR last_name LIKE '%A%');
  4. queryWrapper.like("first_name", "nana").or().like("last_name ","nana");
  5. queryWrapper.ge("actor_id",10);
  6. // 等同于 WHERE actor_id > 10 AND first_name LIKE '%A%' OR last_name LIKE '%A%'; 这种写法是错误得
  1. if (StringUtils.isNotBlank(vo.getTitle())) {
  2. //queryWrapper.like("mt.title", vo.getTitle()).or().like("mt.message", vo.getTitle()); 错误拼接
  3. queryWrapper.and(Wrapper -> Wrapper.like("mt.title", vo.getTitle()).or().like("mt.message", vo.getTitle()));
  4. }
  5. SELECT COUNT(1) FROM message AS m LEFT JOIN message_text AS mt ON m.message_id = mt.id LEFT JOIN (SELECT count(1) AS un_read_count, rec_id FROM message WHERE status = 0 GROUP BY rec_id) AS m1 ON m.rec_id = m1.rec_id WHERE (m.rec_id = ? AND relevance_message_type IN (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) AND mt.update_time <= ? AND mt.update_time >= ? AND
  6. (mt.title LIKE ? OR mt.message LIKE ?)
  7. AND m.deleted = ?)

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

闽ICP备14008679号