参考自:https://blog.csdn.net/u012702547/article/details/88775298
1、pom.xml添加依赖包
<dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.9.2</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.9.2</version> </dependency>
2、添加配置类
@Configuration @EnableSwagger2 public class Swagger2Config { @Bean public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2) .pathMapping("/") .select() .apis(RequestHandlerSelectors.basePackage("com.example.mybatisplus.controller"))// .paths(PathSelectors.any()) .build().apiInfo(apiInfo()); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("测试接口文档") .description("接口文档") .version("1.0") .build(); } }
//标红处记得改为自己包的路径
3、给Controller和Action添加swagger注解
/** * <p> * 控制器 * </p> * * @author jhd * @since 2020-07-02 */ @Api(tags = "测试信息") @RestController @RequestMapping("/test") public class TestController { @Resource private ITestService testService; /** * 通过主键查询单条数据 * * @return 单条数据 */ @ApiOperation("查询单条信息") @GetMapping("selectOne") public Test selectOne() { return this.testService.selectOne(); } }
4、给请求类添加注解
@ApiModel public class Test { @ApiModelProperty(value = "id") private Integer id; @ApiModelProperty(value = "用户名") private String name;//getter/setter用lomlok实现 }
参考网址已经比较完善了,为防止意外再记录一下
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)