Querydsl:BooleanExpression生成意外的括号

时间:2017-11-04 17:09:34

标签: java querydsl

我正在使用querydsl lib生成一个复杂的表达式 - 我想要的输出是 -

e1 = 1 || (e2 = 2&& e3 = 3)

但生成的查询是 - e1 = 1 || e2 = 2&& e3 = 3

以下是代码:

    Predicate exp1 = Expressions.predicate(Ops.EQ,
            Expressions.path(String.class, "e1"),
            Expressions.path(Object.class, "1"));
    Predicate exp2 = Expressions.predicate(Ops.EQ,
            Expressions.path(String.class, "e2"),
            Expressions.path(Object.class, "2"));
    Predicate exp3 = Expressions.predicate(Ops.EQ,
            Expressions.path(String.class, "e3"),
            Expressions.path(Object.class, "3"));

    BooleanBuilder builder = new BooleanBuilder(exp1);
    BooleanBuilder builder2 = new BooleanBuilder(exp2);
    builder2.and(exp3);
    builder.or(builder2);

奇怪的是,如果我在我的代码中反转'和'和'或'运算符,我得到了正确的括号 - e1 = 1&& (e2 = 2 || e3 = 3)

需要一些帮助。感谢

0 个答案:

没有答案