Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the swagger of Springboot project interface

Shulou Source: shulou.com Published: 2022-06-03 16:41:12 11月14日 Update

This article introduces how to use the swagger of the Springboot project interface. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.

The step1:pom file introduces the swagger plug-in

Io.springfox springfox-swagger2 2.9.2 io.springfox springfox-swagger-ui 2.9.2 org.springframework.boot spring-boot-starter-web

Step2: adding SwaggerConfig.java

Package com.ggkt.crm.admin.config;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.service.ApiInfo;import springfox.documentation.spi.DocumentationType;import springfox.documentation.spring.web.plugins.Docket;import springfox.documentation.swagger2.annotations.EnableSwagger2 / * Title: Swagger * Description: interface testing (available or not) * @ author ggkt * * / @ Configuration@EnableSwagger2public class SwaggerConfig {@ Value (value = "${swagger.enabled}") private Boolean swaggerEnabled @ Bean public Docket createAllotManageApi () {return new Docket (DocumentationType.SWAGGER_2) .apiInfo (apiInfo ()) .groupName ("assignment Management") / / whether .enable (swaggerEnabled) .apis (RequestHandlerSelectors. BasePackage ("com.ggkt.crm.admin.allotManage.dataType.controller")) / / specify the path processing PathSelectors.any () represents all paths. Paths (PathSelectors.any ()). Build (). PathMapping ("/") } @ Bean public Docket createMarketManageApi () {return new Docket (DocumentationType.SWAGGER_2) .apiInfo (apiInfo ()) .groupName ("Marketing Management") / / whether .enable (swaggerEnabled) .select () / / scanning path package .apis ( RequestHandlerSelectors.basePackage ("com.ggkt.crm.admin.marketManage")) / / specify the path processing PathSelectors.any () represents all paths. Paths (PathSelectors.any ()). Build (). PathMapping ("/") } @ Bean public Docket createBaseManageApi () {return new Docket (DocumentationType.SWAGGER_2) .apiInfo (apiInfo ()) .groupName ("basic configuration Management") / / whether .enable (swaggerEnabled) .select () / / scanned path package .apis (RequestHandlerSelectors.basePackage ( "com.ggkt.crm.admin.baseManage")) / / specify the path processing PathSelectors.any () represents all paths. Paths (PathSelectors.any ()). Build (). PathMapping ("/") } private ApiInfo apiInfo () {return new ApiInfoBuilder () .title ("interface document") .description ("API") .version ("1.0.0") .build ();}}

Step3:domain class annotation mode

The way step4:Controller classes are annotated

Step5:application.yml configuration

6. Interface access

Http://localhost:9099/admin/swagger-ui.html

This is the end of how to use the swagger of the Springboot project interface. I hope the above content can be helpful to you and learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Path interface representative processing management project content way more comments help configuration good no interest foundation buddy partner plug-in file Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info MySQL NVidia MariaDB vpn