swagger
swagger 接口文档管理可视化工具
一、pom引入依赖
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
二、Swagger3Config.java
package com.jeffcail.otterexam.config;
import io.swagger.annotations.ApiOperation;
import org.springframework.boot.SpringBootConfiguration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
@SpringBootConfiguration
@EnableOpenApi
public class Swagger3Config {
public Docket createRestApi() {
return new Docket(DocumentationType.OAS_30)
.apiInfo(apiInfo())
.enable(false) // ture 启用Swagger3.0, false 禁用(生产环境要禁用)
.select()
.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) // 扫描的路径使用@Api的controller
.paths(PathSelectors.any()) // 指定路径处理PathSelectors.any()代表所有的路径
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("在线考试接口文档")
.description("在线考试接口文档")
.contact(new Contact("jeffcail", "https://blog.caixiaoxin.cn/", "XXXXXX@qq.com"))
.version("1.0")
.build();
}
}
四、配置application.yml
mvc:
pathmatch:
matching-strategy: ant_path_matcher
五、使用
控制器 @Api(tags = “登陆”)
@Api(tags = "登陆")
@RestController
@RequestMapping("/api")
public class LoginController {
方法
@ApiOperation(value = "学生登陆|老师登陆|管理员登陆")
public ResultResponse login(@RequestBody Login login) {
六、效果