文件乱码

yun-zuoyi
汪云昊 5 years ago
parent c5d6607760
commit 0f19f9d4ab

@ -35,6 +35,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedInputStream;
import java.io.IOException;
@ -295,7 +297,7 @@ public class SysFileController extends CoreBaseController {
*/
@GetMapping("/download/{id}")
@ApiOperation(value = "文件下载", notes = "文件下载")
public void singleDownload(@PathVariable("id") String id, HttpServletResponse response) {
public void singleDownload(@PathVariable("id") String id, HttpServletRequest request, HttpServletResponse response) {
try {
startMultiService();
@ -320,8 +322,19 @@ public class SysFileController extends CoreBaseController {
.build();
}
String userAgent = request.getHeader("User-Agent");
String formFileName = sysFile.getFileOriginalName();
// 针对IE或者以IE为内核的浏览器
if (userAgent.contains("MSIE") || userAgent.contains("Trident")) {
formFileName = java.net.URLEncoder.encode(formFileName, "UTF-8");
} else {
// 非IE浏览器的处理
formFileName = new String(formFileName.getBytes("UTF-8"), "ISO-8859-1");
}
response.setContentType("application/force-download"); // 设置强制下载不打开
response.addHeader("Content-Disposition", "attachment;fileName=" + sysFile.getFileOriginalName()); // 设置文件名
response.addHeader("Content-Disposition", "attachment;fileName=" + formFileName); // 设置文件名
response.addHeader("Content-type", FileContentTypeTool.getContentType(StringTool.getStringFileSuffix(sysFile.getFileOriginalName(), true))); // 设置文件名
BufferedInputStream bis = null;

@ -165,21 +165,24 @@ public class SystemInitService implements ISystemInitService {
lanMap.put(res.getLanguageCode(), res.getResourceValue());
// web 资源
if (!webLangMap.containsKey(res.getLanguageCode())) {
webLangMap.put(res.getLanguageCode(), new HashMap<>());
if(res.getResourceType() == CommonEnumUtil.SYS_LOCALE_RESOURCE_TYPE.WEB.getValue()) {
// web 资源
if (!webLangMap.containsKey(res.getLanguageCode())) {
webLangMap.put(res.getLanguageCode(), new HashMap<>());
}
// 放入资源信息
webResMap = webLangMap.get(res.getLanguageCode());
webResMap.put(res.getResourceKey(), res.getResourceValue());
// web 模块资源
softResKey = res.getLanguageCode() + ":" + res.getSoftTypeVal();
if (!webSoftLangMap.containsKey(softResKey)) {
webSoftLangMap.put(softResKey, new HashMap<>());
}
// 放入模块资源信息
webSoftResMap = webSoftLangMap.get(softResKey);
webSoftResMap.put(res.getResourceKey(), res.getResourceValue());
}
// 放入资源信息
webResMap = webLangMap.get(res.getLanguageCode());
webResMap.put(res.getResourceKey(), res.getResourceValue());
// web 模块资源
softResKey = res.getLanguageCode() + ":" + res.getSoftTypeVal();
if (!webSoftLangMap.containsKey(softResKey)) {
webSoftLangMap.put(softResKey, new HashMap<>());
}
// 放入模块资源信息
webSoftResMap = webSoftLangMap.get(softResKey);
webSoftResMap.put(res.getResourceKey(), res.getResourceValue());
}
for (String key : resMap.keySet()) {

Loading…
Cancel
Save