Repository类的定义:

public interface Repository<T, ID extends Serializable> {

}

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

2)如果我们定义的接口EmployeeRepository extends Repository

如果我们自己的接口没有extends Repository,运行时会报错:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springdata.repository.EmployeeRepository' available

3) 添加注解能到达到不用extends Repository的功能
@RepositoryDefinition(domainClass = Employee.class, idClass = Integer.class)

我们写个例子

  

package org.springdata.repository;

import org.springdata.domain.Employee;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.RepositoryDefinition;

/***
 * domainClass  表示哪个实体类 * idClass 标识id
 */
@RepositoryDefinition(domainClass = Employee.class, idClass = Integer.class)
public interface EmployeeRepository /*extends Repository<Employee,Integer>*/ {
    /**
     * 根据名字找员工
     * desc
     * @param name
     * @return
     */
    public Employee findByName(String name);
}

以上 咱们通过一个注解 来什么接口 RepositoryDefinition

04-15 09:03