当前位置:网站首页>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 |
边栏推荐
- What's wrong with running yolov5 (1) p, r, map are all 0
- yolov5 improvement (1) Add attention focus mechanism
- The most complete ever!A collection of 47 common terms of "digital transformation", read it in seconds~
- RowBounds[通俗易懂]
- [ROS] (05) ROS Communication - Node, Nodes & Master
- Verilog学习 系列
- 8580 合并链表
- 【ROS】工控机的软件包不编译
- paddleocr window10初体验
- 第十五单元 分页、过滤
猜你喜欢
随机推荐
paddleocr window10初体验
redis分布式锁和看门狗的实现
yolov5,yolov4,yolov3乱七八糟的
Paddle window10 environment using conda installation
第十三单元 混入视图基类
第八单元 中间件
The IDEA of packaged jar package
Mysql's case the when you how to use
Network pruning (1)
What are the file encryption software?Keep your files safe
云片网案例
deal!It's July 30th!
[ROS] Compiling packages packages encounters slow progress or stuck, use swap
yolov5 improvement (1) Add attention focus mechanism
[ROS]roscd和cd的区别
如何自定义feign方法级别的超时时间
Sentinel源码(六)ParamFlowSlot热点参数限流
Go语言初始
第十四单元 视图集及路由
hsql是什么_MQL语言