我是使用 JPA 的新手,我正在在线阅读教程,所有这些教程都从 JPARespository 扩展而来,如下所示
从此页面
https://www.callicoder.com/spring-boot-jpa-hibernate-postgresql-restful-crud-api-example/
package com.example.postgresdemo.repository;
import com.example.postgresdemo.model.Answer;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface AnswerRepository extends JpaRepository<Answer, Long> {
List<Answer> findByQuestionId(Long questionId);
}
但是在我的项目中 Eclipse 提示以下内容
The type JpaRepository<Property,Long> cannot be the superclass of PropertyRepository; a superclass must be a class
下面是我的课
package realestate.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import realestate.model.Property;
import java.util.List;
@Repository
public class PropertyRepository extends JpaRepository<Property, Long> {
}
最佳答案
基本上,JPA 存储库是接口(interface)。
在您的代码中,您声明了一个类并使用接口(interface)扩展它。 类可以实现接口(interface),但不能扩展它。
因此请将类声明更改为接口(interface),如下所示。
@Repository
public class PropertyRepository extends JpaRepository<Property, Long> {
}
至
@Repository
public interface PropertyRepository extends JpaRepository<Property, Long> {
}
关于java - 存储库未扩展 JpaRepository,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55756272/