《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> {

}

声明:

本文于2019年1月发布在简书。

参考链接:https://www.jianshu.com/p/1ddb5e118edd

发布了44 篇原创文章 · 获赞 41 · 访问量 9031

猜你喜欢

转载自blog.csdn.net/goldentec/article/details/104796129