当前位置:网站首页>Swagger use
Swagger use
2022-06-30 08:14:00 【sashaSloan】
swagger Use
( Novice notes , Crazy Porter )
** This chapter is based on the optimization part of the crazy God Ruiji takeout project
swagger Use
Introduce
Use Swagger You just need to define the interface and the interface related information according to its specifications , Re pass Swagger A series of derived projects and tools , You can generate various formats of interface documents , And online interface debugging page and so on .
Official website : https:/ /swagger.io/
knife4j Is for Java MVC Framework for the integration Swagger Generate Api Document enhancement solution .
swagger Use
swagger To configure
1、 Import maven coordinate
<dependency>
<groupld>com.github.xiaoymin</groupld>
<artifactld>knife4j-spring-boot-starter</artifactld>
<version>3.0.2</version>
</dependency>
2、 Import knife4j Related configuration classes (WebMvcConfig)
stay mvc The configuration file WebMvcConfig In the open swagger and knife4j
@EnableSwagger2
@EnableKnife4j
public class WebMvcConfig extends WebMvcConfigurationSupport {
......
// Create the following two methods in the class
@Bean
public Docket createRestApi()
{
// The document type
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.itheima.reggie.controller"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo(){
return new ApiInfoBuilder()
.title(" Reggie takeout "). version("1.0")
. description(" Reggie takeout interface document ").build() ;
}
3、 Set up static resources ( Otherwise, the interface document page cannot be accessed )
Set static resource mapping (WebMvcConfig Class addResourceHandlers Method ), Otherwise, the interface document page cannot be accessed .
// solve swagger cannot access
registry.addResourceHandler("/swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/doc.html").addResourceLocations("classpath:/META-INF/resources/");
// solve swagger Of js File not accessible
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
4、 stay LoginCheckFilter Set the request path that does not need to be processed in 
visit localhost:8080/doc.html
Here you can see the interface information and test the interface .
swagger Commonly used annotations
Add relevant annotations to classes and methods for configuration 


边栏推荐
- [flower carving experience] 12 build the Arduino development environment of esp32c3
- Applet uses QR code plug-in
- Recurrence relation (difference equation) -- Hanoi problem
- Deep learning -- language model and sequence generation
- 小程序使用二维码插件
- Deep learning - LSTM
- tp5设置直接下载文件
- Acreems energy efficiency management platform escorts the power safety of high-rise residential areas
- 【笔记】Polygon mesh processing 学习笔记(10)
- This point in JS
猜你喜欢
![[tensorflow GPU] building of deep learning environment under windows11](/img/10/6d30d4c310e6677049a1012d47f773.png)
[tensorflow GPU] building of deep learning environment under windows11

Deep learning - residual networks resnets

Sword finger offer II 075 Array relative sort (custom sort, count sort)

Redis design and Implementation (VIII) | transaction

【JUC系列】Fork/Join框架之概览

What are the Amazon evaluation terms?

C # about Net cognition

Cesium learning notes (VI) particle system

mysql无法连接内网的数据库

【NVMe2.0b 14-2】Create/Delete Queue
随机推荐
Construction of energy conservation supervision system for campus buildings of ankery University
领域驱动下cloud项目中单个服务的示例
Tue Jun 28 2022 15:30:29 gmt+0800 (China standard time) date formatting
Sword finger offer II 076 The kth largest number in the array (use heap to solve TOPK problem)
Deep learning - residual networks resnets
End-to-end 3D Point Cloud Instance Segmentation without Detection
C# Console. Writeline() function output format
MySQL加索引语句不加锁:ALGORITHM=INPLACE, LOCK=NONE
TP5 set direct download file
CRM&PM如何帮助企业创造最优销售绩效
鲸探NFT数字臧品系统开发技术分享
Redis设计与实现(三)| 服务器与客户端的交互(事件IO模型)
Sword finger offer II 075 Array relative sort (custom sort, count sort)
[JUC series] overview of fork/join framework
vulfocus入门靶机
[notes] polygon mesh processing learning notes (10)
An example of a single service in a cloud project driven by a domain
C. Fishingprince Plays With Array
涂鸦Wi-Fi&BLE SoC开发幻彩灯带
Using typera+picgo to realize automatic uploading of markdown document pictures