• springBoot Swagger2 接口文档生成


    // 生成配置类
    package com.irm.jd.config.swagger;
    
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import springfox.documentation.builders.ApiInfoBuilder;
    import springfox.documentation.builders.PathSelectors;
    import springfox.documentation.builders.RequestHandlerSelectors;
    import springfox.documentation.service.ApiInfo;
    import springfox.documentation.spi.DocumentationType;
    import springfox.documentation.spring.web.plugins.Docket;
    
    /**
     * 接口文档自动生成配置
     */
    @Configuration
    public class Swagger2Config {
        @Bean
        public Docket createRestApi() {
            return new Docket(DocumentationType.SWAGGER_2)
                    .apiInfo(apiInfo())
                    .select()
                    .apis(RequestHandlerSelectors.basePackage("com.irm.jd.controller"))
                    .paths(PathSelectors.any())
                    .build();
        }
    
        private ApiInfo apiInfo() {
            return new ApiInfoBuilder()
                    .title("IRM 全局API文档")
                    .description("IRM 全局API文档,http://irm.jd.com")
                    .termsOfServiceUrl("http://irm.jd.com")
                    .version("1.0.0")
                    .build();
        }
    }
    
    //开启
    @SpringBootApplication()
    @EnableCaching
    @EnableScheduling
    @MapperScan("com.irm.jd.mapper")
    @EnableAsync
    @EnableSwagger2
    public class IrmApplication extends SpringBootServletInitializer {
    
        @Override
        protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
            return application.sources(IrmApplication.class);
        }
    
        public static void main(String[] args) {
            SpringApplication.run(IrmApplication.class, args);
        }
    }
    
    // 方法上面定义
     @PostMapping("/upload")
        @ApiOperation(value = "脚本上传")
        @ApiImplicitParams({
                @ApiImplicitParam(name = "files",value = "上传的文件",type ="file",paramType = "path",required =true)
        })
        public String uploadScript(List<MultipartFile> files) {
            for (MultipartFile file : files) {
                System.out.println(file);
            }
            return null;
        }
  • 相关阅读:
    《Excel效率手册:早做完,不加班》
    《“胡”说IC——菜鸟工程师完美进阶》
    《UNIX环境高级编程(第3版)》
    《学习R》
    《Netty权威指南》
    《啊哈!算法》
    《流程的永恒之道》
    《算法帝国》
    Guava-Optional可空类型
    guava之Joiner 和 Splitter
  • 原文地址:https://www.cnblogs.com/leigepython/p/10562934.html
Copyright © 2020-2023  润新知