修复部署后文件下载问题
parent
66bdd41ceb
commit
7810744afc
|
|
@ -1,6 +1,5 @@
|
||||||
package com.gunshi.project.xyt.controller;
|
package com.gunshi.project.xyt.controller;
|
||||||
|
|
||||||
import cn.hutool.core.io.resource.ClassPathResource;
|
|
||||||
import com.alibaba.fastjson2.JSON;
|
import com.alibaba.fastjson2.JSON;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||||
|
|
@ -38,21 +37,17 @@ import org.springframework.web.bind.annotation.RequestPart;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 描述: 水质采样记录表
|
* 描述: 水质采样记录表
|
||||||
|
|
@ -195,16 +190,16 @@ public class OsmoticWaterRController {
|
||||||
@PostMapping("/downloadFile")
|
@PostMapping("/downloadFile")
|
||||||
@CrossOrigin
|
@CrossOrigin
|
||||||
public void downloadFile(HttpServletResponse response) throws IOException {
|
public void downloadFile(HttpServletResponse response) throws IOException {
|
||||||
ClassPathResource classPathResource = new ClassPathResource("/doc/2002年6月1日_GB3838-2002地表水环境质量标准.pdf");
|
String filePath = "doc/2002年6月1日_GB3838-2002地表水环境质量标准.pdf";
|
||||||
File file = classPathResource.getFile();
|
File file = new File(filePath);
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
new IllegalArgumentException("文件不存在!");
|
new FileNotFoundException("文件不存在!");
|
||||||
}
|
}
|
||||||
response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(file.getName(), "UTF-8"));
|
response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(filePath, "UTF-8"));
|
||||||
BufferedInputStream inputStream = null;
|
InputStream inputStream = null;
|
||||||
OutputStream outputStream = null;
|
OutputStream outputStream = null;
|
||||||
try {
|
try {
|
||||||
inputStream = new BufferedInputStream(new FileInputStream(file));
|
inputStream = this.getClass().getClassLoader().getResourceAsStream(filePath);
|
||||||
outputStream = response.getOutputStream();
|
outputStream = response.getOutputStream();
|
||||||
byte[] buffer = new byte[1024];
|
byte[] buffer = new byte[1024];
|
||||||
int len = 0;
|
int len = 0;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue