refactor: 根包由 com.bestsch.bschclassmanage 重命名为 com.yunhai.bschclassmanage
- git mv src/main/java/com/bestsch/bschclassmanage -> src/main/java/com/yunhai/bschclassmanage - 255 个 Java 文件的 package/import 同步替换为 com.yunhai.bschclassmanage - pom.xml 项目 groupId 设为 com.yunhai(与外部依赖 com.bestsch:bsch-* 无关,未改动) - IDE 缓存 workspace.xml 路径同步更新(外部依赖坐标 com.bestsch:bsch-* 保持不动)
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
package com.yunhai.bschclassmanage.utils;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.core.io.InputStreamResource;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
@Slf4j
|
||||
public class DownloadFileUtil {
|
||||
|
||||
public static final String separator = File.separator;
|
||||
|
||||
/**
|
||||
* 下载样表
|
||||
* @param filePath 文件上级目录
|
||||
* @param fileName 文件名
|
||||
* @param newName 下载的展示文件名
|
||||
* @return 响应
|
||||
*/
|
||||
public static ResponseEntity<InputStreamResource> download(String filePath, String fileName, String newName) {
|
||||
// String route = "static" + separator + "templates" + separator;
|
||||
// String path = null;
|
||||
ResponseEntity<InputStreamResource> response = null;
|
||||
try {
|
||||
// path = route + filePath + separator + fileName;
|
||||
|
||||
File file = new File(filePath);
|
||||
|
||||
System.out.println(file.exists());
|
||||
|
||||
|
||||
// ClassPathResource classPathResource = new ClassPathResource(filePath);
|
||||
InputStream inputStream = new FileInputStream(file);
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
|
||||
headers.add("Content-Disposition",
|
||||
"attachment; filename="
|
||||
+ new String(newName.getBytes("gbk"), "iso8859-1"));
|
||||
headers.add("Pragma", "no-cache");
|
||||
headers.add("Expires", "0");
|
||||
response = ResponseEntity.ok().headers(headers)
|
||||
.contentType(MediaType.parseMediaType("application/octet-stream"))
|
||||
.body(new InputStreamResource(inputStream));
|
||||
} catch (FileNotFoundException e1) {
|
||||
log.error("找不到指定的文件", e1);
|
||||
} catch (IOException e) {
|
||||
log.error("获取不到文件流", e);
|
||||
}
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user