配置Swagger

1 引入依赖包

复制代码
 1 <dependency>
 2       <groupId>io.springfox</groupId>
 3       <artifactId>springfox-swagger2</artifactId>
 4       <version>2.7.0</version>
 5 </dependency>
 6 <dependency>
 7        <groupId>io.springfox</groupId>
 8        <artifactId>springfox-swagger-ui</artifactId>
 9        <version>2.7.0</version>
10 </dependency>
复制代码

 

2 在config中添加配置类

 

复制代码
 1 @Configuration
 2 @EnableSwagger2
 3 public class Swagger2Config {
 4 
 5     @Bean
 6     public Docket webApiConfig(){
 7         return new Docket(DocumentationType.SWAGGER_2)
 8                 .groupName("webApi")
 9                 .apiInfo(webApiInfo())
10                 .select()
11                 .build();
12 
13     }
14 
15     private ApiInfo webApiInfo(){
16 
17         return new ApiInfoBuilder()
18                 .title("网站-讲师API文档")
19                 .description("本文档描述了讲师服务接口定义")
20                 .version("1.0")
21                 .contact("填入数据")
22                 .build();
23     }
24 }
复制代码

   这个配置类一般都是固定的, 我们只需要直接赋值粘贴使用即可, 对于一些描述性的东西, 我们按照要求填入就好

 

3 使用

  在相应的地方使用最基本的四个注解:

    @Api

    @ApiModel

    @ApiOperation

    @ApiParam

posted @   0龙行者0  阅读(81)  评论(0编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
点击右上角即可分享
微信分享提示