使用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的相关实现代码

 

posted @   abelkeith  阅读(677)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
· 写一个简单的SQL生成工具
点击右上角即可分享
微信分享提示