当前位置:网站首页>St. Regis Takeaway Notes - Lecture 10 Swagger
St. Regis Takeaway Notes - Lecture 10 Swagger
2022-08-02 14:21:00 【Xiao Liyi】
I. Introduction
With Swagger, you only need to define interfaces and interface-related information according to its specifications, and then through a series of projects and tools derived from Swagger, you can generate interface documents in various formats, as well as online interface debugging pagesand many more.
Official website: https://swagger.io/
knife4j is an enhanced solution to generate Api documentation for Java MVC framework integration with Swagger.
Second, how to use
1. Import the maven coordinates of knife4j
com.github.xiaoymin knife4j-spring-boot-starter 3.0.2 2. Import knife4j related configuration classes (WebMvcConfig)
@[email protected]@[email protected] class WebMvcConfig extends WebMvcConfigurationSupport {@Beanpublic Docket createRestApi() {// document typereturn new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select().apis(RequestHandlerSelectors.basePackage("com.jf.controller")).paths(PathSelectors.any()).build();}private ApiInfo apiInfo() {return new ApiInfoBuilder().title("St. Regis Takeaway").version("1.0").description("Regi takeaway interface documentation").build();}
3. Set static resources (addResourceHandlers method in WebMvcConfig), otherwise the interface documentation page cannot be accessed
registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");4. Set the request path that does not need to be processed in LoginCheckFilter
"/doc.html","/webjars/**","/swagger-resources","/v2/api-docs"
Three, Swagger common annotations
| Notes | Description |
|---|---|
| @Api | Used on the requested class, such as Controller, to indicate the description of the class |
| @ApiModel | Used on a class, usually an entity class, representing a message that returns response data |
| @ApiModelProperty | Used on properties to describe the properties of the response class |
| @ApiOperation | Used in the requested method, explaining the purpose and function of the method |
| @ApilmplicitParams | Used in the method of the request, indicating a set of parameter description |
| @ApilmplicitParam | Used in the @ApilmplicitParams annotation to specify aspects of a request parameter |
边栏推荐
猜你喜欢
随机推荐
理解TCP长连接(Keepalive)
深度学习框架pytorch快速开发与实战chapter4
Sentinel源码(一)SentinelResourceAspect
Deep learning framework pytorch rapid development and actual combat chapter3
Cloin 控制台乱码
MarkDown语法汇总
Audio processing: floating point data stream to PCM file
第七单元 ORM表关系及操作
MobileNet ShuffleNet & yolov5替换backbone
政策利空对行情没有长期影响,牛市仍将继续 2021-05-19
yolov5,yolov4,yolov3乱七八糟的
【Tensorflow】AttributeError: '_TfDeviceCaptureOp' object has no attribute '_set_device_from_string'
如何自定义feign方法级别的超时时间
【ROS】编译软件包packages遇到进度缓慢或卡死,使用swap
yolov5 improvement (1) Add attention focus mechanism
8581 Linear linked list inversion
How to solve 1045 cannot log in to mysql server
第十五单元 分页、过滤
[ROS](04)package.xml详解
Paddle window10 environment using conda installation

ROS通信 —— 话题(Topic)通信](/img/21/d79f2c4e246eb9ea39df9c7435bb36.png)

![[ROS] Introduction to common tools in ROS (to be continued)](/img/ea/e390106f750bf697e62a3a296014d2.png)




