当前位置:网站首页>Swagger document configuration
Swagger document configuration
2022-07-03 08:18:00 【Children haha】
swagger:
swagger Is a specification and complete framework , Can generate , describe , Invocation and visualization RESTful Style Web service .
springboot Integrate swagger
Add dependency
There are two patterns , One is swagger-ui.html, One is doc.html( Take according to your own requirements )
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<!--swagger-ui.html Pattern -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<!--doc.html Pattern -->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
<version>1.9.2</version>
</dependency>establish swagger Configuration class :
package com.yan.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;
@Configuration // tell springboot You need to load this configuration class
@EnableSwagger2 // Enable swagger
public class SwaggerConfig {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
// adopt select Return an instance , Used to control which interfaces are exposed to swagger To show .
.select()
// For all api monitor
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
}
// establish api Basic information of ,( This information will be displayed in the document , such as title Describe something like that )
public ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("spring-web project ")
.description(" Description of the project ").build();
}
}
verification :
After the project starts , You can visit localhost:8080/swagger-ui.html perhaps localhost:8080/doc.html Came to visit. .( Choose according to your dependence on import )
Some notes :
Controller layer
Define the interface name :@Api(tags="xxx")
Define method name :@ApiOperation(value="xxx")
Definition param Attributes of parameters :@ApiImplicitParam(name = "xx", value = "xx", paramType = "xx")
Such as : @ApiImplicitParam(name = "pid", value = " product id", paramType = "String")
Entity
Define object name :@ApiModel("xxx")
Define the parameter name :@ApiModelProperty(value = "xxx")边栏推荐
猜你喜欢

Lua framwrok framework starts

Kwai 20200412 recruitment
![[end of 2021] National Meteorological Short Video (Kwai, Tiktok) influence list in December](/img/51/81ceaf8746ec7455ea8abf9f038e81.jpg)
[end of 2021] National Meteorological Short Video (Kwai, Tiktok) influence list in December

Redis data structure

the installer has encountered an unexpected error installing this package

Some understandings of 3dfiles

详解sizeof、strlen、指针和数组等组合题

Multi traveling salesman problem -- overview of formula and solution process

Youyou1 of xlua knapsack system

Unity2019_ Natural ambient light_ Sky box
随机推荐
Editor Extensions
Golang 中string和int类型相互转换
Demonstration of plug-in use of ventuz basic series
ArrayList
Ventuz Foundation Series "one step at the door"
Product creation and commercial realization of chat robot (according to La Ma Bang - Dr. Wang Jingjing - speech)
Unity2019_ Lighting system
Exe file running window embedding QT window
Use of ue5 QRcode plug-in
Uniapp learning records
十六进制编码简介
What is BFC?
CLion-Toolchains are not configured Configure Disable profile问题解决
freetype库的移植
Transplantation of tslib Library
UE4 plug in development
Base64 and base64url
【云原生】微服务之Feign的介绍与使用
idea取消引用顯示效果
KunlunBase MeetUP 等您来!