In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "what are the steps of springboot integration swagger". In daily operation, I believe many people have doubts about what the steps of springboot integration swagger are. Xiaobian consulted various materials and sorted out simple and easy operation methods. I hope to help you answer the doubts of "what are the steps of springboot integration swagger"! Next, please follow the small series to learn together!
Step 1: maven Import Swagger as follows:
io.springfox
springfox-swagger2
2.2.2
io.springfox
springfox-swagger-ui
2.2.2
Step 2: Create the Swagger2 configuration class as follows:
/**
*
*/
package swagger.config;
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;
/**
* @author ignore1992
*
*/
@Configuration
@EnableSwagger2
public class SwaggerConfig
{
@Bean
public Docket createDocket()
{
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(createApiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("swagger.api.controller"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo createApiInfo()
{
return new ApiInfoBuilder()
.title("springboot uses swagger2")
.description("Generate corresponding interface document")
.termsOfServiceUrl("https://blog.csdn.net/ignorewho")
.contact("ignore1992")
.version("1.0")
.build();
}
}
Step 3: In this way, you can use the annotations provided by swagger to complete the description, invocation, generation, etc.
Common comments are as follows:
@Api : Used on a class to describe the main purpose of the class.
@ApiOperation: Used on methods to add method descriptions to APIs.
@ApiImplicitParams : Used on methods and contains a set of parameter descriptions.
@ApiImplicitParam: Used to annotate method arguments.
Use cases are as follows:
/**
*
*/
package swagger.api.controller;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
/**
* @author ignore1992
*
*/
@RestController
@RequestMapping(value = "/swaggerapi")
public class SwaggerApiController
{
@ApiOperation(value = "Test swaggerapi interface method")
@RequestMapping(value = "/test", method = RequestMethod.GET)
public String test()throws Exception
{
return "swaggerapi test";
}
} At this point, the study of "what are the steps of springboot integration swagger" is over, hoping to solve everyone's doubts. Theory and practice can better match to help everyone learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.