zoukankan      html  css  js  c++  java
  • JAVA学习之路 swagger

    参考自: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实现
    }

    参考网址已经比较完善了,为防止意外再记录一下

  • 相关阅读:
    android-基础编程-RecyclerView
    android-基础编程-ListView
    LINUX 日志服务器的搭建
    使用parted进行磁盘分区
    raid磁盘阵列
    LVM逻辑卷管理
    /home 分区迁移试验
    PHP 匹配一个汉字
    xhr dojo load
    ERR: Call to undefined function openssl_random_pseudo_bytes()
  • 原文地址:https://www.cnblogs.com/jianghaidong/p/13231049.html
Copyright © 2011-2022 走看看