简单通用SwaggerConfig配置类,swagge类似于postman

1、引入依赖

io.springfox

springfox-swagger2

provided

io.springfox

springfox-swagger-ui

provided

2、SwaggerConfig配置类,直接复制到项目

/**

* @author linZT

* swagger文档

*/

@Configuration

@EnableSwagger2

public class SwaggerConfig {

//页面接口文档1

@Bean

public Docket adminApiConfig(){

return new Docket(DocumentationType.SWAGGER_2)

.groupName("adminApi")

.apiInfo(adminApiInfo())

.select()

.paths(Predicates.not(PathSelectors.regex("/admin/.*")))

.paths(Predicates.not(PathSelectors.regex("/error.*")))

.build();

}

private ApiInfo adminApiInfo(){

return new ApiInfoBuilder()

.title("swagger,后台接口测试")

.description("本文档描述了后台项目中的接口定义")

.version("1.0")

.contact(new Contact("linZT", "http://linZT.com", "1591731944@qq.com"))

.build();

}

//页面接口文档2

@Bean

public Docket webApiConfig(){

return new Docket(DocumentationType.SWAGGER_2)

.groupName("webApi")

.apiInfo(webApiInfo())

.select()

//只显示api路径下的页面

.paths(Predicates.and(PathSelectors.regex("/api/.*")))

.build();

}

private ApiInfo webApiInfo(){

return new ApiInfoBuilder()

.title("前台网站-API文档")

.description("本文档描述了前台网站微服务接口定义")

.version("1.0")

.contact(new Contact("linZT", "http://linZT.com", "1591731944@qq.com"))

.build();

}

//页面接口文档...

}

3、swagger使用方式(注解)

@Api(tags = "用户模块管理") //swagger注解

@RestController

@RequestMapping("/admin/userInfo")

public class UserInfoController {

@Autowired

UserInfoService userInfoService;

@ApiOperation(value = "获取所有用户信息接口")//swagger注解

@GetMapping("/findAll")

public Result findAll(){

List list = userInfoService.list();

return Result.ok(list);

}

}

相关阅读

评论可见,请评论后查看内容,谢谢!!!
 您阅读本篇文章共花了: