今天在做一个浏览器下载文件的功能,文件下载的功能是实现了,但下载的文件
名字出现了中文乱码
下面是代码
``` @RequestMapping(value = "download")
public ResponseEntity export(Long filePath) {
HzAttachmentRecord hzAttachmentRecord = hzAttachmentRecordDao.selectByPrimaryKey(filePath);
HttpHeaders headers = new HttpHeaders();
File file = new File(hzAttachmentRecord.getAttachmentUrl()+"\\"+hzAttachmentRecord.getRealName());
if(file==null){
return null;
}
try {
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
headers.setContentDispositionFormData("attachment", hzAttachmentRecord.getShowName());
return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file),
headers, HttpStatus.CREATED);
}catch (Exception e){
return new ResponseEntity(null,headers,HttpStatus.NOT_FOUND);
}
}
下面是问题截图
![图片说明](https://img-ask.csdn.net/upload/201812/07/1544169029_180503.jpg)
debug测试了下,attachment对应的值是正确的文件名,应该是传输到前端
时编码格式有点问题
大概情况就是这样,网上找了小半天也没找到解决方法,有没有大佬知道怎么
解决,万分感谢