V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
abcdxx
V2EX  ›  Java

spring boot jpa 查询问题

  •  
  •   abcdxx · 2018-06-10 17:31:59 +08:00 · 1696 次点击
    这是一个创建于 2118 天前的主题,其中的信息可能已经有所发展或是发生改变。

    代码

    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<>?));
    

    有大神指导下没 😄

    4 条回复    2018-06-14 08:41:50 +08:00
    abcdxx
        1
    abcdxx  
    OP
       2018-06-10 17:36:05 +08:00
    airfling
        2
    airfling  
       2018-06-10 18:50:59 +08:00 via Android
    jpa 不是可以直接加注解写自定义的 sql 吗
    ukipoi
        4
    ukipoi  
       2018-06-14 08:41:50 +08:00
    感觉 A&B or C&D 和 (A&B) or (C&D)一样
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1018 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 19:43 · PVG 03:43 · LAX 12:43 · JFK 15:43
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.