gpt4 book ai didi

swagger-ui - Springfox swagger-ui 3.0.0 不会调出swagger-ui.html页面

转载 作者:行者123 更新时间:2023-12-03 21:49:23 28 4
gpt4 key购买 nike

我正在将 springfox swagger-ui 与 Springboot 一起使用,但未为分段上传启用 fileUpload 按钮。我尝试升级到 springfox-swagger-ui 3.0.0 但这甚至没有打开 swagger-ui 页面。有没有办法获得文件上传按钮?
我的 API 调用如下所示:

@RequestMapping(value = "/foo", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)

public ResponseEntity<ByteArrayResource> method(@RequestParam("file") MultipartFile file, @RequestParam("id") String id) {
....
}
springfox-swagger-ui 2.10.5 的当前问题
Upload file button missing
enter image description here
    My pom.xml is : 
<properties>
<java.version>1.8</java.version>
<io.springfox.version>3.0.0</io.springfox.version>
</properties>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${io.springfox.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.10.5</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-data-rest</artifactId>
<version>${io.springfox.version}</version>
</dependency>

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>${io.springfox.version}</version>
</dependency>

最佳答案

来自:http://springfox.github.io/springfox/docs/current/#migrating-from-existing-2-x-version
有一些事情需要做:
1. 将 springfox-boot-starter 添加到 POM 中,从 POM 中删除旧的依赖项: springfox-swagger2 和 springfox-swagger-ui

    <dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>

2. 移除@EnableSwagger2 注释

@Configuration
// remove @EnableSwagger2
public class SwaggerConfig {

@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2).select()
.apis(RequestHandlerSelectors.basePackage(UserManagementImpl.class.getPackage().getName()))
.paths(PathSelectors.any()).build();
}
}

3. 对请求使用@RequestPart("files")

@ApiOperation(value = "files", notes = "upload user emails from CSV and email content from json and send out")
@PostMapping(path = "/users/uploadUserEmailsAndSend", consumes = { "multipart/form-data" })
@ResponseBody
ResponseEntity<UploadUsersResDTO> uploadUserEmailsAndSend(@RequestPart("files") MultipartFile[] filesUpload){

CSVParser csvParser = null;
BufferedReader fileEmailsReader = null;
BufferedReader fileEmailMessageReader = null;
MultipartFile fileCSV = null;
MultipartFile fileJson = null;

try {
if (filesUpload[0].getOriginalFilename().toLowerCase().endsWith("csv")) {
fileCSV = filesUpload[0];
fileJson = filesUpload[1];
} else {
fileCSV = filesUpload[1];
fileJson = filesUpload[0];
}
// more codes ....
}

4. 访问 swagger:http://localhost:8080/swagger-ui/
enter image description here

关于swagger-ui - Springfox swagger-ui 3.0.0 不会调出swagger-ui.html页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63275134/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com