zoukankan      html  css  js  c++  java
  • Swagger使用

    1. Maven依赖

    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <version>2.6.1</version>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>2.6.1</version>
    </dependency>
    

    2. 配置类

    @Configuration
    @EnableSwagger2
    public class Swagger {
        @Bean
        public Docket docket() {
            return new Docket(DocumentationType.SWAGGER_2)
                    .apiInfo(apiInfo())
                    .select()
                    .apis(RequestHandlerSelectors.basePackage("com.example.demo.controller"))
                    .paths(PathSelectors.any())
                    .build();
        }
    
        public ApiInfo apiInfo() {
            return new ApiInfoBuilder()
                    .title("PM Supply")
                    .description("版本")
                    .termsOfServiceUrl("")
                    .version("1.0")
                    .build();
        }
    }
    

    3. 示例

    @Api(value = "用户管理类")
    @RestController
    @RequestMapping(value = "user")
    public class UserController {
    
        @RequestMapping(value = "/user", method = RequestMethod.POST)
        @ApiOperation(value = "增加一个用户")
        public String addUser(@RequestBody User user) {
            return user.getName();
        }
    }
    

    4. 访问URL

    http://localhost:8080/swagger-ui.html

    @Api(value = "用户管理类")
    @RestController
    @RequestMapping(value = "user")
    public class UserController {

    @RequestMapping(value = "/user", method = RequestMethod.POST)
    @ApiOperation(value = "增加一个用户")
    public String addUser(@RequestBody User user) {
    return user.getName();
    }
    }
  • 相关阅读:
    node同时验证手机号和座机号
    导入excle到服务器时候删除服务器历史数据
    杂七杂八
    c# 导出表格 api
    c# 导出表格
    element split 将多个单号分隔
    vue 前台传后台
    vue.js 使用时间组件 日期少一天的问题
    layui 文字滚动
    CRT&&EXCRT学习笔记
  • 原文地址:https://www.cnblogs.com/oxygenG/p/13394638.html
Copyright © 2011-2022 走看看