spring boot jpa 查询问题

2018-06-10 17:31:59 +08:00
 abcdxx

代码

Predicate exp1 = cb.and(cb.equal(root.get("day"), "2018-01-02"), cb.equal(root.get("frequency"), 200));
Predicate exp2 = cb.and(cb.equal(root.get("day"), "2018-01-01"), cb.notEqual(root.get("frequency"), 100));
Predicate p2 = cb.or(exp1,exp2);

代码生成的 sql 是:

select * from stat_report report0_ where (report0_.day=? and report0_.frequency=? or report0_.day=? and report0_.frequency<>?);

我想生成的 sql 是:

select * from stat_report report0_ where ((report0_.day=? and report0_.frequency=? ) or (report0_.day=? and report0_.frequency<>?));

有大神指导下没 😄

1708 次点击
所在节点    Java
4 条回复
abcdxx
2018-06-10 17:36:05 +08:00
airfling
2018-06-10 18:50:59 +08:00
jpa 不是可以直接加注解写自定义的 sql 吗
sagaxu
2018-06-11 09:47:28 +08:00
ukipoi
2018-06-14 08:41:50 +08:00
感觉 A&B or C&D 和 (A&B) or (C&D)一样

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/461945

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX