java - 存储库未扩展 JpaRepository

标签 java spring spring-boot spring-data-jpa

我是使用 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/

相关文章:

spring - 在 REST 中,我们如何处理返回资源集合的多种方式?

java - 为什么 ListDataModel 不能使用有界类型参数?

java - 一次在面板中添加多个项目

java - Spring MVC 请求/ session 作用域 bean 线程安全

spring.config.location 在 Spring Boot 2.0.0 M6 上不起作用

deployment - 无法在 Jelastic 上部署 Spring boot 应用程序

java - 为什么会出现堆栈溢出错误?

java - 如何检测 Jscrollpane 中的滚动条被拖动/单击?

spring-boot - Spring Security 登录页面 - 图片

java - 如何使用Spring Boot从数据库创建实体类?