由于在使用Swagger2过程中,出现如下错误!而一时之间又没法找从出处,故被迫升级处理bug…
主要是队友开发没有留意,挖坑…
引入Maven包
<!--MP依赖文件 基于3.x版本-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
配置swagger
package com.abcdef.onecard.config;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
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.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
/**
* API接口界面--swagger-ui.html
* @Date 2021/04/30 9:00
**/
@Configuration
@EnableOpenApi
public class Swagger2Config {
@Value("${
swagger3.enable}")
private boolean enableSwagger;
@Value("${
swagger3.stu-url}")
private String stuUrl;
/**
* 用于配置swagger2,包含文档基本信息
* 指定swagger2的作用域(这里指定包路径下的所有API)
* @return Docket
*/
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.OAS_30)
.pathMapping("/")
// 是否启用
.enable(enableSwagger)
// Swagger UI 头部信息
.apiInfo(apiInfo())
// 指定生成文档的接口
.select()
.apis(RequestHandlerSelectors.basePackage("com.abcdef.onecard.controller"))
.paths(PathSelectors.any())
.build();
}
/**
* 构建文档基本信息,用于页面显示,可以包含版本、
* 联系人信息、服务地址、文档描述信息等
* @return ApiInfo
*/
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
//标题
.title("SpringBoot3-API")
.description("一卡通手动同步接口API")
.termsOfServiceUrl(stuUrl + "/swagger-ui.html")
//设置联系方式
//.contact(new Contact("任工", "www.baidu.com", "[email protected]"))
.version("1.0")
.build();
}
}
开启swagger
#Swagger3 是否开启
swagger3:
enable: true
#title: Swagger3 demo
#description: Swagger3 demo api document
stu-url: http://127.0.0.1:9090
控制层添加注解
@Api(tags = "系统管理-用户管理")
@ApiOperation(value = "模糊查询", notes = "用户-模糊查询")
@ApiImplicitParam(name = "sysUserVo", value = "新增对象JSON", required = true, dataType = "SysUserVo")
效果图
访问地址: http://127.0.0.1:9090/swagger-ui/