整合swagger

整合swagger

Swagger简介

(12条消息) swagger使用教程——快速使用swagger_其实不会敲代码的博客-CSDN博客_swagger使用

Step

  1. maven依赖
  2. 配置SwaggerConfig(作者,项目名,邮件等)
  3. 启动后访问路径Swagger UI

使用

  • 实体类中
    • @ApiModel类描述
    • @ApiModelProperty类中字段描述
  • 控制器中
    • @Api控制器描述
    • @ApiOperation接口描述
1
2
3
4
5
6
7
8
9
10
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package com.jcDemo.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
*@author:gao_quansui
*@user:ASUS
*@date:2022/9/22- 10:08
*@projectName:jc_demo
*/
@Configuration
public class SwaggerConfig {
@Bean
public Docket docket() {
return new Docket(DocumentationType.OAS_30).apiInfo(
new ApiInfoBuilder()
.contact(new Contact("gqs", "", ""))
.title("JC_Demo")
.build()
);
}
}