默认行为是所有给定的 'AND' 连接FilterExpression
。
为了使这一点更明确以及允许“或”连接,您可以考虑构建FilterExpression
“外部”,例如:
import io.vavr.collection.List;
...
List<ExpressionFluentHelper<YOUR_ENTITY>> expressions = List.empty();
if (zipCode != null) {
expressions = expressions.append(Address.ZIPCODE.eq(zipCode););
}
if (street != null) {
expressions = expressions.append(Address.STREET.eq(street));
}
AddressFluentHelper queryHelper = service.getAllAddress();
if (!expressions.isEmpty()) {
// this combines all elements in the "expressions" via "or", starting from the left/the first entry
ExpressionFluentHelper<YOUR_ENTITY> combinedExpression = expressions.reduceLeft(ExpressionFluentHelper::or);
queryHelper.filter(combinedExpression);
}