Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem of file download garbled and Knife4j.txt in swagger-bootstrap-ui upgrade Knife4j

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article is about how to solve the swagger-bootstrap-ui upgrade Knife4j file download garbled and Knife4j.txt problems. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

I. preparation for upgrading Knife4j

Dependency introduction

Com.github.xiaoymin knife4j-spring-boot-starter

Annotations open

@ EnableSwagger2@EnableKnife4jpublic class SwaggerAutoConfiguration {/ /.} 2. File download API

Download garbled problem

The garbled code problem occurs because Knife4j does not support @ PostMapping file cache, so you need to convert the interface to GetMapping.

Download the file as Knife4j.txt

The file stream is empty

Configure produces = MediaType.APPLICATION_OCTET_STREAM_VALUE for GetMapping

Set the response header (note spaces and commas)

Response.setHeader ("Content-Disposition", "attachment;filename=" + URLEncoder.encode (fileName, "utf-8"))

Get request does not support request parameter cache, and it is very inconvenient to reset the parameters every time a file is downloaded.

Post request is not supported for file download

If the returned data is too large, the page will be very stuck. It is not recommended to upgrade knife4j.

Thank you for reading! On "how to solve swagger-bootstrap-ui upgrade Knife4j file download garbled and Knife4j.txt problems" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, you can share it out for more people to see it!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report