来自
docs
要使用自定义功能丰富存储库,您首先要定义自定义功能的接口和实现。使用您提供的存储库界面扩展自定义界面。
像这样定义一个接口
public interface StudentRepositoryCustom { List<String> nameByCourse(String coursename);}然后像这样定义此接口的自定义实现
@Serviceclass StudentRepositoryImpl implements StudentRepositoryCustom { @PersistenceContext private EntityManager em; public List<String> nameByCourse(String coursename) { CriteriaBuilder cb = em.getCriteriaBuilder(); //Using criteria builder you can build your criteria queries. }}现在,您可以像这样在JPA存储库中扩展此自定义存储库实现。
public interface StudentRepository extends CrudRepository<StudentEntity, Integer>, StudentRepositoryCustom {}了解有关条件查询和条件构建器的更多信息
here



