我尝试使用
Spring Data中的
PagingAndSortingRepository
:
import org.springframework.data.jpa.repository.JpaRepository;
public interface StudentRepository extends JpaRepository<Student, Integer> {}
但是我收到此错误:
无法解决org.springframework.data.repository.PagingAndSortingRepository
我的代码有什么问题以及如何修复它?
这个解决了我的问题
摇篮
// https://mvnrepository.com/artifact/org.springframework.data/spring-data-jpa
compile group: 'org.springframework.data', name: 'spring-data-jpa', version: '2.0.1.RELEASE'
Maven
<!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-jpa -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>2.0.1.RELEASE</version>
</dependency>
删除 ~.m2/org/springframework.data 文件夹并更新 maven 项目。
如果您有
<artifactId>spring-data-commons</artifactId>
依赖性并且 <artifactId>spring-data-jpa</artifactId>
两者都有,那么就会出现此问题。
删除
<artifactId>spring-data-commons</artifactId>
依赖项。
您使用的是JPA Repository 但发生的情况是,maven 要么没有更新所有必需的文件。所以为了获取所需的所有文件,我们可以更新 maven,以便它可以获取所有文件
或者我们可以 将扩展 JPA Repository 更改为 CRUD Repository,然后将其更改为 JPA Repository 它的作用是,它首先访问 CRUD 所需的所有文件,并且它适用于 JPA 存储库
这对我有用