当前位置:网站首页>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")
边栏推荐
- An intern's journey to cnosdb
- Clion toolchains are not configured configure disable profile problem solving
- IP production stream is so close to me
- 方正锐利重磅升级到12.0版本,包装印前处理更加便捷、高效!
- C#课程设计之员工信息管理系统
- Unity2019_ Natural ambient light_ Sky box
- 链式长取值
- Dotween plug-in
- Editor Extensions
- Ilruntime learning - start from scratch
猜你喜欢
随机推荐
What is BFC?
P2704 [NOI2001] 炮兵阵地(状压dp)
P2622 light off problem II (state compression search)
Scite change background color
Get to know unity2 for the first time
Generate video using clipout in viz engine
matlab神经网络所有传递函数(激活函数)公式详解
Minimap plug-in
Osgearth north arrow display
Student educational administration management system of C # curriculum design
【音视频】ijkplayer错误码
Wpf: solve the problem that materialdesign:dialoghost cannot be closed
数据分析练习题
Why can void * be a general pointer
Golang's range
C#课程设计之学生教务管理系统
超限黑客认知
方正锐利重磅升级到12.0版本,包装印前处理更加便捷、高效!
数据的存储
MAE