您的位置:首页 > 编程语言 > Java开发

Spring Data

2017-06-26 00:00 85 查看
原文参考 : https://es.yemengying.com/4/4.1.html (spring data elasticsearch 对spring data的讲解)

1.spring- Data repository

The central interface in Spring Data repository abstraction is Repository (probably not that much of a surprise). It takes the domain class to manage as well as the id type of the domain class as type arguments. This interface acts primarily as a marker interface to capture the types to work with and to help you to discover interfaces that extend this one. The CrudRepository provides sophisticated CRUD functionality for the entity class that is being managed.

译文:Spring数据存储库抽象的中心接口是存储库(可能不太令人惊讶)。它需要域类来管理,以及域类的id类型作为类型参数。该接口主要作为一个标记接口,用于捕获与工作相关的类型,并帮助您发现扩展该类型的接口。CrudRepository为正在管理的实体类提供复杂的CRUD功能。

Example 1. CrudRepository interface

public interface CrudRepository<T, ID extends Serializable>
extends Repository<T, ID> {

<S extends T> S save(S entity);

T findOne(ID primaryKey);

Iterable<T> findAll();

Long count();

void delete(T entity);

boolean exists(ID primaryKey);

// … more functionality omitted.
}

2.PagingAndSortingRepository

On top of the CrudRepository there is a PagingAndSortingRepository abstraction that adds additional methods to ease paginated access to entities

译文:CrudRepository的顶部有一个PagingAndSortingRepository抽象,增加了额外的方法来缓解分页的访问实体

Example 2. PagingAndSortingRepository

public interface PagingAndSortingRepository<T, ID extends Serializable>
extends CrudRepository<T, ID> {

Iterable<T> findAll(Sort sort);

Page<T> findAll(Pageable pageable);
}

例如 通过20个页面的大小访问用户的第二页,你可以这样做:

PagingAndSortingRepository<User, Long> repository = // … get access to a bean
Page<User> users = repository.findAll(new PageRequest(1, 20));

.
.
.
.
.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息