Spring-data

2020-01-02  本文已影响0人  一直想上树的猪

一、Repository

Repository类的定义:

public interface Repository<T, ID extends Serializable> {

}

二、Repository接口详解

1)Repository是一个空接口,标记接口
没有包含方法声明的接口

2)如果我们定义的接口EmployeeRepository extends Repository,就会被spring所管理

如果我们自己的接口没有extends Repository,运行时会报错:

org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.tinner.repository.EmployeeRepository' available

3) 添加注解能到达到不用extends Repository的功能

@RepositoryDefinition(domainClass = Employee.class, idClass = Integer.class)

三、Repository的子接口

四、弊端

对于按照方法命名规则来使用的话,有弊端:

五、@Query注解

六、事务在Spring data中的使用:

七、相关代码

相关代码链接:https://github.com/jinping-dev/spring-data

上一篇下一篇

猜你喜欢

热点阅读