0

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
} 
membersound
  • 81,582
  • 193
  • 585
  • 1,120
  • in route 'min' you can do route.departure.after(value), in route 'max' route.departure.before(value), so you get departure > min && departure < max – 9900kf Nov 08 '22 at 06:17
  • In this specific case - yes. But it's just an example, and the question targets "cross field references" in general. – membersound Nov 08 '22 at 13:29

1 Answers1

-1

It should be that Querydsl cannot generate a Q object. I am looking for a similar method. You can refer to thisanswer

young
  • 19
  • 3