【发布时间】:2019-01-09 12:32:46
【问题描述】:
我想实现Specifications 并想使用findAll(Specification<T> spec) 方法,但是当我插入规范时,Eclipse 总是告诉我:
The method findAll(Sort) in the type JpaRepository<Telefonbuch,Long> is not applicable for the arguments (Specification<Telefonbuch>)
我不想使用Sort。我交出了一个规范,为什么它总是尝试使用带有排序的方法?
您可以在这里看到该方法是 Eclipse 的建议: https://imgur.com/a/LuF6ZGK
规格:
public interface Specification<T> {
Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder builder);
}
Telefonbuch 规格:
public static Specification<Telefonbuch> hasVorname(String vorname) {
return (root, query, cb) -> {
return cb.equal(root.get(Telefonbuch_.vorname), "%"+vorname.toLowerCase()+"%");
};
}
TelefonbuchRepository:
public interface TelefonbuchRepository extends JpaRepository<Telefonbuch, Long>, JpaSpecificationExecutor<Telefonbuch> {
搜索控制器:
public void search(String vorname, String nachname, String telefonnummer, String handynummer) {
if (!vorname.isEmpty()) {
List<Telefonbuch> list = telefonbuchRepository.findAll(TelefonbuchSpecifications.hasVorname(vorname));
}
这里是
List<Telefonbuch> list = telefonbuchRepository.findAll(TelefonbuchSpecifications.hasVorname(vorname));
}
它告诉我:
The method findAll(Sort) in the type JpaRepository<Telefonbuch,Long> is not applicable for the arguments (Specification<Telefonbuch>)
【问题讨论】:
标签: java spring-data-jpa spring-data specifications