我遵循了本指南(https://www.baeldung.com/rest-api-search-querydsl-web-in-spring-data-jpa)来实现QueryDSL WebSupport。
我想将querydsl注入到来自我的存储库的自定义find方法中。像这样的东西:
@RequestMapping(method = RequestMethod.GET, value = "/readings")
List<Reading> findAll( @QuerydslPredicate(root = Reading.class) Predicate predicate, long id{
return repo.findByBasketId(predicate,id);
}
有没有办法做到这一点?我需要重写findAll方法吗?如果是,怎么办?
谢谢
实际上,这是我在存储库中的代码:
public interface ReadingRepository extends JpaRepository<Reading,Integer> , QuerydslPredicateExecutor<Reading>, QuerydslBinderCustomizer<QReading> {
List<Reading> findByBasketId(Basket basket);
///other declarations
@Override
default public void customize(QuerydslBindings bindings, QReading root) {
bindings.bind(String.class).first(
(StringPath path, String value) -> path.containsIgnoreCase(value));
}
}