提交 396b4b93 authored 作者: gongwenjie's avatar gongwenjie

通知

上级 12d75595
...@@ -130,22 +130,23 @@ public class ExcelController { ...@@ -130,22 +130,23 @@ public class ExcelController {
@ApiOperation(value = "下载通讯录模板") @ApiOperation(value = "下载通讯录模板")
@PostMapping("/download") @PostMapping("/download")
public ResponseEntity download(HttpServletRequest request, HttpServletResponse response) throws Exception { public ResponseEntity download(HttpServletRequest request, HttpServletResponse response) throws Exception {
ClassPathResource resource = new ClassPathResource("address.xls");
String filename= "address.xls"; String filename= "address.xls";
File file = ResourceUtils.getFile("classpath:address.xls"); // File file = ResourceUtils.getFile("classpath:address.xls");
// File file = new File("src/main/resources/address.xls"); // File file = new File("src/main/resources/address.xls");
// System.out.println(addressUrl); // System.out.println(addressUrl);
// System.out.println("存在??"); // System.out.println("存在??");
if(file.exists()){ //判断文件父目录是否存在 // if(file.exists()){ //判断文件父目录是否存在
// response.setContentType("application/vnd.ms-excel;charset=UTF-8"); // response.setContentType("application/vnd.ms-excel;charset=UTF-8");
// response.setCharacterEncoding("UTF-8"); // response.setCharacterEncoding("UTF-8");
// response.setHeader("Content-Disposition", "attachment;fileName=" + java.net.URLEncoder.encode(filename,"UTF-8")); // response.setHeader("Content-Disposition", "attachment;fileName=" + java.net.URLEncoder.encode(filename,"UTF-8"));
byte[] buffer = new byte[1024]; byte[] buffer = new byte[1024];
FileInputStream fis = null; //文件输入流 InputStream fis = resource.getInputStream(); //文件输入流
BufferedInputStream bis = null; BufferedInputStream bis = null;
OutputStream os = null; //输出流 OutputStream os = null; //输出流
try { try {
os = response.getOutputStream(); os = response.getOutputStream();
fis = new FileInputStream(file); // fis = new FileInputStream(file);
bis = new BufferedInputStream(fis); bis = new BufferedInputStream(fis);
int i = bis.read(buffer); int i = bis.read(buffer);
while(i != -1){ while(i != -1){
...@@ -168,7 +169,7 @@ public class ExcelController { ...@@ -168,7 +169,7 @@ public class ExcelController {
e.printStackTrace(); e.printStackTrace();
logger.error(e.getMessage()); logger.error(e.getMessage());
} }
} // }
return ok("下载失败"); return ok("下载失败");
} }
......
...@@ -12,7 +12,7 @@ server.ssl.keyStoreType=PKCS12 ...@@ -12,7 +12,7 @@ server.ssl.keyStoreType=PKCS12
server.ssl.keyAlias= alias server.ssl.keyAlias= alias
#mongodb configuration #mongodb configuration
spring.data.mongodb.uri=mongodb://localhost:27017/notes6 spring.data.mongodb.uri=mongodb://localhost:27017/notes5
# servlet configuration # servlet configuration
spring.servlet.multipart.max-file-size=100MB spring.servlet.multipart.max-file-size=100MB
spring.servlet.multipart.max-request-size=1000MB spring.servlet.multipart.max-request-size=1000MB
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论