spring-boot-swagger
一、创建项目
spring-boot 搭建web项目 - hehehenhen - 博客园 (cnblogs.com)
二、导入依赖
<dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.7.0</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.7.0</version> </dependency>
三、创建api
package cn.newstrength.api; import cn.newstrength.pojo.QueryPageRequest; import cn.newstrength.pojo.QueryResponseResult; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.springframework.web.bind.annotation.RequestBody; import java.util.Map; /** * 说明: * * @author LanPengBiao * @version 1.0 * @Date: Created in 2021-10-29 9:32 */ @Api(value="cms页面管理接口",description = "cms页面管理接口,提供页面的增、删、改、查") public interface UserControllerApi { //页面查询 @ApiOperation("分页查询页面列表") @ApiImplicitParams({ @ApiImplicitParam(name="page",value = "页码",required=true,paramType="query",dataType="int"), @ApiImplicitParam(name="size",value = "每页记录数",required=true,paramType="query",dataType="int") }) public Map findList( int page, int size); }
四、创建controller
package cn.newstrength.controller; import cn.newstrength.api.UserControllerApi; import cn.newstrength.pojo.Page; import cn.newstrength.pojo.QueryPageRequest; import cn.newstrength.pojo.QueryResponseResult; import org.springframework.web.bind.annotation.*; import java.util.HashMap; import java.util.Map; @RestController public class UserController implements UserControllerApi{ @PostMapping("getUser") public Map findList(int page, int size) { Map map = new HashMap(); map.put(page, size); return map; } }
五、注释启动类
启动
package cn.newstrength; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import springfox.documentation.swagger2.annotations.EnableSwagger2; @SpringBootApplication @EnableSwagger2 public class ManageApplication { public static void main(String[] args) { SpringApplication.run(ManageApplication.class); } }
六、查看接口
网址:
http://localhost:8080/swagger-ui.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律