1.Swagger
1.1 介绍
Swagger 是一个规范和完整的Web API框架,用于生成、描述、调用和可视化 RESTful 风格的 Web 服务。
功能主要包含以下几点:
A. 使得前后端分离开发更加方便,有利于团队协作;
B. 接口文档在线自动生成,降低后端开发人员编写接口文档的负担;
C. 接口功能测试;
1.2 项目集成Swagger
- 引入swagger依赖;
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
</dependency>
- 定义swagger配置类;
@Configuration
@EnableSwagger2
public class SwaggerConfiguration {
@Bean
public Docket buildDocket() {
//构建在线API概要对象
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(buildApiInfo())
.select()
// 要扫描的API(Controller)基础包
.apis(RequestHandlerSelectors.basePackage("com.stock.Controller"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo buildApiInfo() {
//网站联系方式
Contact contact = new Contact