• Swagger2使用------------整合SpringBoot


    什么是swagger2


    编写和维护接口文档是每个程序员的职责,根据Swagger2可以快速帮助我们编写最新的API接口文档,再也不用担心开会前仍忙于整理各种资料了,间接提升了团队开发的沟通效率。

    常用注解


    swagger通过注解表明该接口会生成文档,包括接口名、请求方法、参数、返回信息的等等。

    @Api:修饰整个类,描述Controller的作用
    @ApiOperation:描述一个类的一个方法,或者说一个接口
    @ApiParam:单个参数描述
    @ApiModel:用对象来接收参数
    @ApiModelProperty:用对象接收参数时,描述对象的一个字段
    @ApiImplicitParam:一个请求参数
    @ApiImplicitParams:多个请求参数
     

     swagger2怎么用?

    1.导入pom依赖

    
        2.9.2
    
    
        io.springfox
        springfox-swagger2
        ${swagger.version}
    
    
        io.springfox
        springfox-swagger-ui
        ${swagger.version}
    

    2.配置 SwaggerConfiguration配置类

    @Configuration
    @EnableSwagger2
    public class SwaggerConfiguration {
    
        @Bean
        public Docket docket(){
            return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo());
        }
        private ApiInfo apiInfo(){
            Contact ct = new Contact("cm", "http://cm.sina.cn", "cm@sina.com");
            return new ApiInfo("我的塔吊信息测试","塔吊基础信息测试....","v1.0","http://www.bdqn.cn",ct,"学术部 2.0许可","许可连接",new ArrayList());
        }
    }
    

    3.controller层加注解 Api()

     

    @Api()
    @RestController
    @RequestMapping("/tcinfo")
    public class TcinfosCtrl {
    /**
     * 6 按照用户传入的塔机编号 查询塔机信息
     * @param tcid
     * @return
     */
    
    @GetMapping("/findTcById")
    @ApiOperation("按照用户传入的塔机编号 查询塔机信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tcid",value = "吊塔编号",required = true,paramType = "query",dataType = "int")
    })
    public TcinfosVO findById(@RequestParam(value = "tcid")Integer tcid){
        Tcinfos tic = tcinfoStoreService.findTcByTcid(tcid);
        TcinfosVO tvo = new TcinfosVO();
        BeanUtils.copyProperties(tic,tvo);
        return tvo;
    }
    

    }

     

    4 启动   浏览器输入地址 开始接口测试

    http://localhost:9090/swagger-ui.html#/

    //9090 用自己的端口 

     

     

  • 相关阅读:
    QT 信号与槽
    java设计模式
    Python Requests 丨爬虫基础入门
    nginx 发布vue项目 页面刷新出现404问题
    牛客刷题总结——Python入门:输入输出、字符串、类型转换
    【数据结构】初探时间与空间复杂度:算法评估与优化的基础
    C语言:用递归函数求斐波拉契数
    如何高效管理自己的电脑?文件再多也不乱!
    PHP+mysql的在线考试系统的设计与实现
    使用 docker-compose 部署 golang 的 Athens 私有代理
  • 原文地址:https://blog.csdn.net/just_learing/article/details/125909926