使用swagger或者knife4j在2.0.X或3.0.X版本上传文件域不出现的问题,请求格式自动默认为body的问题
作者:互联网
解决方法
其中最关键的是: 参数 paramType="query"
@ApiImplicitParam(name = "file", value = "文件流对象,接收数组格式", required = true, dataType = "__File",paramType = "query") @PostMapping("/importData") @ResponseBody public Result uploadFile(@RequestParam(value = "file") MultipartFile[] files) throws Exception{ MultipartFile file = files[0]; }
原因:
暂时推测为:openApi3.0和Swagger不兼容导致
解决之后的效果:
knfie4j的配置文件如下:
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.Contact; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2; @Configuration @EnableSwagger2 public class Knife4jConfiguration { @Bean(value = "defaultApi2") public Docket defaultApi2() { Docket docket=new Docket(DocumentationType.SWAGGER_2).enable(true) .apiInfo(new ApiInfoBuilder() .title("XX导入服务") .description("XX导入服务") .termsOfServiceUrl("") .contact(new Contact("lzy","","luziyangwork@foxmail.com")) .version("1.0") .build()) //分组名称 .groupName("1.0版本") .select() //这里指定Controller扫描包路径 .apis(RequestHandlerSelectors.basePackage("core.controller")) .paths(PathSelectors.any()) .build(); return docket; } }
其中引用了springfox包,其中引用了openApi的相关实现代码
标签:body,knife4j,springfox,documentation,value,import,2.0,Docket,public 来源: https://www.cnblogs.com/abelkeith/p/16111588.html