当前位置:网站首页>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 |
边栏推荐
猜你喜欢
随机推荐
AWVS工具介绍[通俗易懂]
YOLOv7使用云GPU训练自己的数据集
logback源码阅读(二)日志打印,自定义appender,encoder,pattern,converter
paddleocr window10 first experience
STM32(F407)—— 堆栈
动手学ocr(一)
yolov5 improvement (1) Add attention focus mechanism
[ROS] The software package of the industrial computer does not compile
Linux:CentOS 7 安装MySQL5.7
第四单元 路由层
Sentinel源码(四)(滑动窗口流量统计)
第十五单元 分页、过滤
瑞吉外卖笔记——第10讲Swagger
How to solve 1045 cannot log in to mysql server
rpm包的卸载与安装[通俗易懂]
第十二单元 关联序列化处理
Unit 4 Routing Layer
8583 顺序栈的基本操作
理解TCP长连接(Keepalive)
Audio processing: floating point data stream to PCM file








创建ROS工作空间](/img/2a/11e5023ef6d052d98b4090d2eea017.png)