* A great real world example of mediator pattern is **traffic control room** at airports. If all flights will have to interact with each other for finding which flight is going to land next, it will create a big mess.
Memento 设计模式是行为模式,是 Gang of Four 讨论的 23 种[设计模式](https://howtodoinjava.com/gang-of-four-java-design-patterns/)之一。 **纪念图案**用于将对象的状态恢复到先前的状态。 也称为**快照模式**。
在上面的类图中,我们为 Mac 和 Linux 操作系统配置了路由器。 如果我们还需要添加 Windows 功能,那么我不需要更改任何类,只需定义一个新的访问者 WindowsConfigurator 并实现 RouterVisitor 接口中定义的 visit()方法。 它将提供所需的功能,而无需任何进一步的修改。
我们将首先创建一些 REST API,这些 API 将用于展示 Swagger 文档功能。 我们将使用 Spring 引导样式公开剩余的 API,以缩短开发时间。
1.Create a Spring boot project from [Spring Boot initializer](https://start.spring.io/) portal with `Web`, `Rest Repositories`, `Actuator` dependencies. Give other maven GAV coordinates and download the project. This screen will look like:
1.从具有 Web,Rest Repositories,Actuator 依赖项的 [Spring Boot 初始化器](https://start.spring.io/)门户创建一个 Spring Boot 项目。 给出其他 Maven GAV 坐标并下载项目。 该屏幕如下所示:
Actually `swagger` API has couple of varieties and maintained in different artifacts. Today we will use the `springfox` because this version adapts well with any spring based configurations. We can try other configurations also easily and that should give same functionality – with no/little change in configuration.
实际上,`swagger` API 具有多种变体,并且维护在不同的工件中。 今天,我们将使用`springfox`,因为该版本可以很好地适应任何基于 spring 的配置。 我们还可以轻松地尝试其他配置,并且应该提供相同的功能-无需更改/只需稍作更改即可。
#### 添加 Swagger2 配置
...
...
@@ -233,17 +233,17 @@ public class Swagger2UiConfiguration extends WebMvcConfigurerAdapter
#### 验证 Swagger2 JSON 格式文档
执行 maven 并启动服务器。 打开链接[http:// localhost:8080 / swagger2-demo / v2 / api-docs](http://localhost:8080/swagger2-demo/v2/api-docs),它应该以`JSON`格式提供整个文档。 这并不是那么容易阅读和理解,实际上 Swagger 已经提供了将其用于其他系统中的功能,例如如今流行的 API 管理工具,它提供了 API 网关,API 缓存,API 文档等功能。
执行 maven 并启动服务器。 打开链接`http://localhost:8080/swagger2-demo/v2/api-docs`,它应该以`JSON`格式提供整个文档。 这并不是那么容易阅读和理解,实际上 Swagger 已经提供了将其用于其他系统中的功能,例如如今流行的 API 管理工具,它提供了 API 网关,API 缓存,API 文档等功能。
![Swagger2 UI Docs without Annotations](img/de00227979aa13b38e66dc6d767ad0be.png)
...
...
@@ -253,7 +253,7 @@ Swagger2 UI 文档(无注释)
## Swagger2 注释
默认生成的 API 文档很好,但是缺少详细的 API 级别信息。 Swagger 提供了一些注释,可以将这些详细信息添加到 API。 例如
默认生成的 API 文档很好,但是缺少详细的 API 级别信息。 Swagger 提供了一些注释,可以将这些详细信息添加到 API。 例如:
1.`@Api` – 我们可以将此注释添加到控制器,以添加有关控制器的基本信息。
...
...
@@ -265,7 +265,7 @@ Swagger2 UI 文档(无注释)
}
```
2.`@ApiOperation and @ApiResponses` – We can add these annotations to any rest method in the controller to add basic information related to that method. e.g.
*[java.sql.DriverManager#getConnection()](https://docs.oracle.com/javase/10/docs/api/java/sql/DriverManager.html#getConnection%28java.lang.String%29"driver manager get connection")
*[java.net.URL#openConnection()](https://docs.oracle.com/javase/10/docs/api/java/net/URL.html#openConnection%28%29"url open connection")