'How to access cross-field values in QueryDSL QuerydslBinderCustomizer?
How can I access other query parameter values inside QuerydslBinderCustomizer
?
My goal is to create a departure.between(min, max)
binding, that I want to derive from two query params min
and max
.
Problem is that the route.max
value is not accessible inside the customize()
method, or at least I don't know how to access it.
/departures?min=2021-01-01&max=2021-01-30
@Repository
public interface RouteRepository extends JpaRepository<Route, Long>,
QueryDslPredicateExecutor<QRoute>, QuerydslBinderCustomizer<QRoute> {
@Override
default public void customize(QuerydslBindings bindings, QRoute route) {
//value is the 'min' query parameter. HOW can I access the 'max' parameter here??
bindings.bind(route.min).first((path, value) -> route.departure.between(value, route.max));
}
}
@Entity
class Route {
@Id long id;
@Transient LocalDate min, max; //only for the query
LocalDate departure; //real db field
}
Solution 1:[1]
It should be that Querydsl cannot generate a Q object. I am looking for a similar method. You can refer to thisanswer
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | young |