Java 存储库未扩展JpaRepository
我不熟悉使用JPA,我正在网上阅读教程,所有这些教程都是从JPA positionory扩展而来的,如下所示 从本页Java 存储库未扩展JpaRepository,java,spring,spring-boot,spring-data-jpa,Java,Spring,Spring Boot,Spring Data Jpa,我不熟悉使用JPA,我正在网上阅读教程,所有这些教程都是从JPA positionory扩展而来的,如下所示 从本页 package com.example.postgresdemo.repository; 导入com.example.postgresdemo.model.Answer; 导入org.springframework.data.jpa.repository.JpaRepository; 导入org.springframework.stereotype.Repository; 导入
package com.example.postgresdemo.repository;
导入com.example.postgresdemo.model.Answer;
导入org.springframework.data.jpa.repository.JpaRepository;
导入org.springframework.stereotype.Repository;
导入java.util.List;
@存储库
公共接口应答库扩展了JpaRepository{
列表findByQuestionId(长问题ID);
}
但在我的项目中,Eclipse抱怨如下
The type JpaRepository<Property,Long> cannot be the superclass of PropertyRepository; a superclass must be a class
类型JpaRepository不能是PropertyRepository的超类;超类必须是类
下面是我的班级
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> {
}
package realestate.repository;
导入org.springframework.data.jpa.repository.JpaRepository;
导入org.springframework.stereotype.Repository;
导入realestate.model.Property;
导入java.util.List;
@存储库
公共类PropertyRepository扩展了JpaRepository{
}
JPA的存储库是接口
在代码中声明了一个类并将其扩展到接口
类可以实现接口。因此,请更改为如下界面
@Repository
public class PropertyRepository extends JpaRepository<Property, Long> {
}
@存储库
公共类PropertyRepository扩展了JpaRepository{
}
到
@存储库
公共接口属性repository扩展了JpaRepository{
}
请注意,Spring数据的主要好处是您不必为应答库编写实现类
;Spring会自动为您实现。您不能用接口实现接口,只需将其编辑到类中即可。@sanjeetpal,您可能会误解这个概念。我同意你的观点(接口不能实现另一个接口)。但我并没有用另一个接口实现接口。我只是用另一个接口扩展接口。
@Repository
public class PropertyRepository extends JpaRepository<Property, Long> {
}
@Repository
public interface PropertyRepository extends JpaRepository<Property, Long> {
}