abcdxx
V2EX  ›  Java

spring boot jpa 查询问题

  •  
  •   abcdxx · Jun 10, 2018 · 2274 views
    This topic created in 2920 days ago, the information mentioned may be changed or developed.

    代码

    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 replies    2018-06-14 08:41:50 +08:00
    abcdxx
        1
    abcdxx  
    OP
       Jun 10, 2018
    airfling
        2
    airfling  
       Jun 10, 2018 via Android
    jpa 不是可以直接加注解写自定义的 sql 吗
    ukipoi
        4
    ukipoi  
       Jun 14, 2018
    感觉 A&B or C&D 和 (A&B) or (C&D)一样
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5116 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 09:39 · PVG 17:39 · LAX 02:39 · JFK 05:39
    ♥ Do have faith in what you're doing.