我想创建自己的自定义Spring Data JPA find方法,该方法采用Integer,Specification和Pageable。
我尝试过创建类似的方法
Page<Student> findAllByGroupId(Integer id, Specification<Student> specification, Pageable pageable);
但这不起作用。
用户存储库
@Repository
public interface UserRepository<T extends User> extends PagingAndSortingRepository<T, Integer>,
JpaSpecificationExecutor<T> {
}
学生资料库
@Repository
public interface StudentRepository extends UserRepository<Student>{
Page<Student> findAllByGroupId(Integer id, Specification<Student> specification, Pageable pageable);
}
服务
@Override
public Page<Student> getGroupStudents(Integer id, StudentQuery studentQuery, Pageable pageable) {
Specification<Student> specification =
studentSpecification.getSpecification(studentQuery);
return studentRepository.findAllByGroupId(id, specification, pageable);
}
当我尝试这个时我得到
java.lang.IllegalArgumentException: At least 2 parameter(s) provided but only 1 parameter(s) present in query.
有什么方法可以创建采用Integer,Specification和Pageable的自定义查找方法?