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

 

 

 

 

 

posted @   hehehenhen  阅读(31)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示