当前位置:网站首页>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
边栏推荐
猜你喜欢
How to handle the expired data of redis and what are the elimination mechanisms?
1. Problems related to OpenGL window and environment configuration
【NVMe2.0b 14】NVMe Admin Command Set
Transformer architecture understanding
多快好省,低门槛AI部署工具FastDeploy测试版来了!
Deep learning - bounding box prediction
Redis design and Implementation (VIII) | transaction
C # about Net cognition
Wsl2 using GPU for deep learning
Redis 的过期数据如何处理,淘汰机制都有那些?
随机推荐
Unit Test
跳槽字节跳动很难嘛?掌握这些技巧,你也能轻松通过
Transformer architecture understanding
Palindrome substring, palindrome subsequence
Recurrence relation (difference equation) -- Hanoi problem
F12抓包用于做postman接口测试的全过程解析
Simple application of generating function
Introduction to opencv (I): image reading and display
[flower carving experience] 14 line blank board pingpong library test external sensor module (one)
Environment configuration of ROS Aubo manipulator
Cesium learning notes (II) uploading data using rest API
How CRM & PM helps enterprises create optimal sales performance
Want to ask, how to choose securities companies for stock speculation? Is it safe to open an account online?
Simple application of generating function -- integer splitting 2
Implementation of remote monitoring by camera in Experiment 5
Cesium learning notes (VI) particle system
Deep learning - goal orientation
[notes] polygon mesh processing learning notes (10)
Pycharm Dlib library installation
微信公众号第三方平台开发,零基础入门。想学我教你啊