配置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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通