> For the complete documentation index, see [llms.txt](https://potoyang.gitbook.io/spring-in-action-v5/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://potoyang.gitbook.io/spring-in-action-v5/di-12-zhang-xiang-ying-shi-chi-jiu-hua-shu-ju/12.1-li-jie-spring-data-xiang-ying-shi-li-cheng/12.1.1-spring-data-xiang-ying-shi-jing-sui.md).

# 12.1.1 Spring Data 响应式精髓

Spring Data 响应式的本质上可以概括为：Repository 可以接受和返回 Mono 和 Flux，而不是某个实体和集合。当 Repository 的方法获取 `Ingredient` 对象时，接口声明可能如下：

```java
Flux<Ingredient> findByType(Ingredient.Type type);
```

如上可见，这个 `findByType()` 方法返回一个 `Flux<Ingredient>`， 而不是一个非响应式接口的 `List<Ingredient>` 或 `Iterable<Ingredient>`。

同样，在保存 Taco 时，Repository 会有一个 `saveAll()` 方法，其接口定义像下面这样：

```java
<Taco> Flux<Taco> saveAll(Publisher<Taco> tacoPublisher);
```

在本例中，`saveAll()` 方法接受一个 Publisher 类型的 Taco（`Mono<Taco>` 或`Flux<Taco>`），并返回 `Flux<Taco>`。这与非响应式不同，非响应式的 `save()` 方法直接接受 Taco 对象并返回保存的 Taco 对象。

简单地说，Spring Data 响应式 Repository 共享一个与非响应式几乎相同的编程模型。就像第3章中所描述的那样。唯一的实质性区别在于，响应式 Repository 的方法要输入和返回 Flux 和 Mono类型，而不是原始的实体类型和集合。
