TestRepository ***extends*** JpaRespotiroy<Test,Long>
JpaRepository是一个接口。为什么我们要扩展它,而不是像我们在Java中所知道的那样实现它?据我所知,接口是实现的,而不是扩展的。
有人能给我解释一下吗?
我假设您的代码看起来像
interface TestRepository extends JpaRepository<Test, Long>
所以TestRepository是一个接口,接口可以扩展其他接口而不是实现接口。
TestRepository将在运行时基于SimpleJpaRepository 从Spring Data JPA实现
https://github.com/spring-projects/spring-data-jpa/blob/main/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java
在Java 中
- 类扩展类
class Test Extends Thread
- interface扩展接口
public interface TestI extends Runtime
- 类实现接口
public class Test implements Runnable