Sprint Boot 中使用 Swagger

1. Pom 文件中添加 Swagger 依赖

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>2.2.2</version>
</dependency>
  

2. Application 类添加 @EnableSwagger2 注解

@SpringBootApplication
@EnableSwagger2
public class Application {
    public static void main(String args) {
        SpringApplication.run(Application.class, args);
    }
}
  

3. 通过注解添加 Api 说明

@Api(value = "xxx 控制器", tags = "标签") // 用于 Controller
@ApiOperation(value = "xxx 接口", notes = "接口说明") // 用于接口方法
@ApiModel("xxx 模型") // 用于模型
@ApiModelProperty("xxx 属性") // 用于模型属性
  

4. 查看接口文档

打开 http://localhost:8080/swagger-ui.html 查看接口文档。

相关文章

  1. Swagger 使用总结

  2. Swagger - 前后端分离后的契约