首页 > 解决方案 > 如何访问 QueryDSL QuerydslBinderCustomizer 中的跨字段值?

问题描述

如何访问内部的其他查询参数值QuerydslBinderCustomizer

我的目标是创建一个departure.between(min, max)绑定,我想从两个查询参数minmax.

问题是方法route.max内部无法访问该值customize(),或者至少我不知道如何访问它。

/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
} 

标签: javaspringspring-data-jpaquerydsl

解决方案


推荐阅读