《Spring Data JPA编程指南》之Repository

Spring Data

1、说明

该接口为中央Repository标记接口。捕获要管理的领域类型以及领域类型的id类型。

  • 一般用途是保存类型信息,并能够在类路径扫描期间发现扩展此接口的接口,以便轻松创建Spring bean。
  • 扩展此接口的域Repository可以通过简单地声明与CrudRepository中声明的方法具有相同签名的方法来选择性地公开CRUD方法。

2、参数说明

  • T :Repository管理的领域类型。
  • ID:Repository管理的实体的id的类型

3、源码

Repository.java源码:

package org.springframework.data.repository;

import org.springframework.stereotype.Indexed;

/**
 * Central repository marker interface. Captures the domain type to manage as well as the domain type's id type. General
 * purpose is to hold type information as well as being able to discover interfaces that extend this one during
 * classpath scanning for easy Spring bean creation.
 * <p>
 * Domain repositories extending this interface can selectively expose CRUD methods by simply declaring methods of the
 * same signature as those declared in {@link CrudRepository}.
 * 
 * @see CrudRepository
 * @param <T> the domain type the repository manages
 * @param <ID> the type of the id of the entity the repository manages
 * @author Oliver Gierke
 */
@Indexed
public interface Repository<T, ID> {

}

Repository.java源码注释翻译:

package org.springframework.data.repository;

import org.springframework.stereotype.Indexed;

/**
 * 中央Repository标记接口。捕获要管理的领域类型以及领域类型的id类型。 
 * 一般用途是保存类型信息,并能够在类路径扫描期间发现扩展此接口的接口,以便轻松创建Spring bean。
 * 扩展此接口的域Repository可以通过简单地声明与{@link CrudRepository}中声明的方法具有相同签名的方法来选择性地公开CRUD方法。
 * 
 * @see CrudRepository
 * @param <T> Repository管理的领域类型。
 * @param <ID> Repository管理的实体的id的类型
 * @author 奥利弗.基尔克
 */
@Indexed
public interface Repository<T, ID> {

}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容