SwaggerUI整合SpringBoot
简介:SwaggerUI与SpringBoot项目整合
| |
| <dependency> |
| <groupId>io.springfox</groupId> |
| <artifactId>springfox-boot-starter</artifactId> |
| <version>3.0.0</version> |
| </dependency> |
- SwaggerConfiguration配置类开发
| @Component |
| @EnableOpenApi |
| @Data |
| public class SwaggerConfiguration { |
| |
| |
| |
| |
| |
| @Bean |
| public Docket webApiDoc() { |
| |
| return new Docket(DocumentationType.OAS_30) |
| .groupName("用户端接口文档") |
| .pathMapping("/") |
| |
| |
| .enable(true) |
| |
| |
| .apiInfo(apiInfo()) |
| .select() |
| .apis(RequestHandlerSelectors.basePackage("net.xdclass")) |
| |
| .paths(PathSelectors.ant("/api/**")) |
| .build() |
| |
| .globalRequestParameters(globalReqeustParameters()) |
| .globalResponses(HttpMethod.GET,getGlabalResponseMessage()) |
| .globalResponses(HttpMethod.POST,getGlabalResponseMessage()); |
| |
| |
| } |
| |
| |
| |
| |
| |
| |
| |
| @Bean |
| public Docket adminApiDoc() { |
| |
| return new Docket(DocumentationType.OAS_30) |
| .groupName("管理端接口文档") |
| .pathMapping("/") |
| |
| |
| .enable(true) |
| |
| |
| .apiInfo(apiInfo()) |
| .select() |
| .apis(RequestHandlerSelectors.basePackage("net.xdclass")) |
| |
| .paths(PathSelectors.ant("/admin/**")) |
| .build(); |
| } |
| |
| |
| private ApiInfo apiInfo() { |
| return new ApiInfoBuilder() |
| .title("1024电商平台") |
| .description("微服务接口文档") |
| .contact(new Contact("小滴课堂-二当家小D", "https://xdclass.net", "微信 xdclass6")) |
| .version("v1.0") |
| .build(); |
| } |
| |
| |
| |
| |
| |
| |
| |
| private List<RequestParameter> globalReqeustParameters() { |
| |
| List<RequestParameter> parameters = new ArrayList<>(); |
| parameters.add(new RequestParameterBuilder() |
| .name("token") |
| .description("登录令牌") |
| .in(ParameterType.HEADER) |
| .query(q -> q.model(m -> m.scalarModel(ScalarType.STRING))) |
| .required(false) |
| .build()); |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| return parameters; |
| |
| } |
| |
| |
| |
| |
| |
| |
| private List<Response> getGlabalResponseMessage() { |
| |
| List<Response> list = new ArrayList<>(); |
| list.add(new ResponseBuilder() |
| .code("4xx") |
| .description("请求错误,根据code和msg检查") |
| .build()); |
| |
| return list; |
| } |
| } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY