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;
    }

 

posted @ 2019-03-20 09:40  雷神约  阅读(202)  评论(0编辑  收藏  举报