【Knife4j】解决SpringBoot整合Knife4j 3.0.3 文件上传不显示文件域

网友投稿 1677 2022-05-29

一、环境版本

springBoot 2.5.2

Knife4J 3.0.3

二、问题

使用Knife4j用来配置接口文档注解的时候,文件上传加不上去,使用注解@ApiParam的type或者format都不行。

三、解决方案

先看源码,位置在/Users/diandianxiyu_geek/.m2/repository/org/springframework/spring-web/5.3.8/spring-web-5.3.8.jar!/org/springframework/web/bind/annotation/RequestPart.class。

package org.springframework.web.bind.annotation; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import org.springframework.core.annotation.AliasFor; @Target({ElementType.PARAMETER}) @Retention(RetentionPolicy.RUNTIME) @Documented public @interface RequestPart { @AliasFor("name") String value() default ""; @AliasFor("value") String name() default ""; boolean required() default true; }

1

2

3

4

5

6

7

8

【Knife4j】解决SpringBoot整合Knife4j 3.0.3 文件上传不显示文件域

9

10

11

12

13

14

15

16

17

18

19

20

21

22

控制器用法如下,亲测可用。

@ApiOperation(value = "导入") @PostMapping("/import") public void importFile(@RequestPart @RequestParam("file") MultipartFile file){ }

1

2

3

4

5

最后生成的文档如下。

Spring Boot

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:qt5.14.2银河麒麟操作系统交叉编译
下一篇:SpringBoot系列之外部配置用法简介
相关文章