• spring swagger2配置


    1.集成jar包

        compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.9.2'
        compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.9.2'
    

    2.新建config类

    @Configuration
    @EnableSwagger2
    public class SwaggerConfig {
        public Docket buildDocket(){
            return  new Docket(DocumentationType.SWAGGER_2)
                    .apiInfo(buildApiInfo())
                    .select()
                    .apis(RequestHandlerSelectors.basePackage("com.example.demo"))
                    .paths(PathSelectors.any())
                    .build();
        }
    
        private ApiInfo buildApiInfo(){
            return  new ApiInfoBuilder()
                    .title("api接口文档")
                    .version("2.2.2")
                    .description("框架基础接口文档")
                    .contact(new Contact("test","www.baidu.com","he.zhao@chwang.ai"))
                    .build();
        }
    }

    3.controller中使用注解

    @RestController
    @RequestMapping(value = "/api/product")
    @Api(tags = "商品")
    public class ProductCtrl {
    
        @ApiOperation(httpMethod = "GET", value = "商品推荐", notes = "首页商品推荐")
        @RequestMapping(value = "/recommend")
        public String recommend() {
            return "";
        }
    
        @ApiOperation(httpMethod = "POST", value = "商品详情", notes = "点击商品/图片查看商品详情")
        @RequestMapping(value = "/productInfo")
        public String productInfo() {
            return "";
        }
    
    }

    4.启动spring boot,访问 http://localhost:8080/swagger-ui.html

  • 相关阅读:
    七、python抽象
    六、python条件、循环及其它语句
    泛型数组
    判断数组是否包含此元素
    数组倒序
    Class字节码文件获取的三种方法
    操作系统的产生
    Java重载的概述
    表设计遵循的三大范式实例
    pyqt5窗体分隔
  • 原文地址:https://www.cnblogs.com/6324/p/11356800.html
Copyright © 2020-2023  润新知