当前位置:网站首页>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 |
边栏推荐
猜你喜欢
8581 线性链表逆置
Unit 11 Serializers
Supervision strikes again, what about the market outlook?2021-05-22
YOLOv7使用云GPU训练自己的数据集
Sentinel源码(四)(滑动窗口流量统计)
Chapter6 visualization (don't want to see the version)
第十五单元 分页、过滤
Flask项目的完整创建 七牛云与容联云
chapter7
【Tensorflow】AttributeError: '_TfDeviceCaptureOp' object has no attribute '_set_device_from_string'
随机推荐
Supervision strikes again, what about the market outlook?2021-05-22
redis分布式锁和看门狗的实现
Flask框架
第十二单元 关联序列化处理
About the development forecast of the market outlook?2021-05-23
使用云GPU+pycharm训练模型实现后台跑程序、自动保存训练结果、服务器自动关机
8581 Linear linked list inversion
【Tensorflow】AttributeError: '_TfDeviceCaptureOp' object has no attribute '_set_device_from_string'
配置zabbix自动发现和自动注册。
chapter7
chapter6可视化(不想看版)
deal!It's July 30th!
xshell连接虚拟机步骤_建立主机与vm虚拟机的网络连接
跑跑yolov5吧
如何选择正规的期货交易平台开户?
史上最全!47个“数字化转型”常见术语合集,看完秒懂~
How to solve 1045 cannot log in to mysql server
ZABBIX配置邮件报警和微信报警
如何自定义feign方法级别的超时时间
[ROS]ROS常用工具介绍(待续)