我不知道我是否可以在两个表达式之间应用“ if-else”语句:
public Predicate build(CriteriaBuilder builder, Root<Person> root) {
Expression<BigDecimal> value_a_1 = root.get(value_a_1);
Expression<BigDecimal> value_a_2 = root.get(value_a_2);
Expression<BigDecimal> value_b_1 = root.get(value_b_1);
Expression<BigDecimal> value_b_2 = root.get(value_a_2);
// Here I want to check if one of the _b values is null or 0 (I hope it is correct):
Expression<Boolean> isValueNullOrZero = builder.or(
value_b_1.isNull(), value_b_1.in(BigDecimal.ZERO),
value_b_2.isNull(), value_b_2.in(BigDecimal.ZERO));
// And then I want to do something like this:
Expression<BigDecimal> value_c_1 = isValueNullOrZero ? value_a_1 : value_b_1;
Expression<BigDecimal> value_c_2 = isValueNullOrZero ? value_a_2 : value_b_2;
// etc
...
}