From e8ff4bcf25c32c84df56a93f6463d606ee7a90a6 Mon Sep 17 00:00:00 2001 From: gaohanghang <1341947277@qq.com> Date: Mon, 6 May 2019 15:08:51 +0800 Subject: [PATCH 1/2] =?UTF-8?q?1.=20=E4=B8=8B=E8=BD=BD=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=83=BD=E6=AD=A3=E5=B8=B8=E6=98=BE=E7=A4=BA=E4=B8=AD=E6=96=87?= =?UTF-8?q?=202.=20application.properties=E6=B7=BB=E5=8A=A0=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=B8=8A=E4=BC=A0=E5=A4=A7=E5=B0=8F=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ramostear/application/controller/FileController.java | 6 ++++-- src/main/resources/application.properties | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/ramostear/application/controller/FileController.java b/src/main/java/com/ramostear/application/controller/FileController.java index 5aaf860..fcb924e 100644 --- a/src/main/java/com/ramostear/application/controller/FileController.java +++ b/src/main/java/com/ramostear/application/controller/FileController.java @@ -15,6 +15,7 @@ import javax.annotation.PostConstruct; import java.io.*; +import java.net.URLEncoder; import java.util.Collection; import java.util.HashMap; import java.util.Map; @@ -90,13 +91,14 @@ public String fileUpload(@RequestParam("file") MultipartFile file) throws IOExce @GetMapping("/download/{fileName}") @ResponseBody - public ResponseEntity downloadFile(@PathVariable(name = "fileName") String fileName) throws FileNotFoundException { + public ResponseEntity downloadFile(@PathVariable(name = "fileName") String fileName) throws FileNotFoundException, UnsupportedEncodingException { File file = new File ( fileUploadRootDir+fileName); InputStreamResource resource = new InputStreamResource ( new FileInputStream ( file ) ); HttpHeaders headers = new HttpHeaders(); - headers.add ( "Content-Disposition",String.format("attachment;filename=\"%s",fileName)); + // 使用URLEncoder.encode(fileName, "UTF-8") 下载文件能正常显示中文 + headers.add ( "Content-Disposition",String.format("attachment;filename=\"%s", URLEncoder.encode(fileName, "UTF-8"))); headers.add ( "Cache-Control","no-cache,no-store,must-revalidate" ); headers.add ( "Pragma","no-cache" ); headers.add ( "Expires","0" ); diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index b69e90b..71cd5e3 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -4,6 +4,8 @@ spring.freemarker.suffix=.html spring.freemarker.enabled=true spring.freemarker.charset=UTF-8 spring.freemarker.template-loader-path=classpath:/templates/ +spring.servlet.multipart.max-file-size=100MB +spring.servlet.multipart.max-request-size=1000MB file.upload.root.dir.windows = C:/work/upload/ file.upload.root.dir.mac = ~/upload/ file.upload.root.dir.linux = ~/upload/ \ No newline at end of file From 4c9e5cac43a1c9d016507aad3daa84f4ef9ebad6 Mon Sep 17 00:00:00 2001 From: gaohanghang <1341947277@qq.com> Date: Fri, 24 May 2019 20:22:57 +0800 Subject: [PATCH 2/2] =?UTF-8?q?<=E5=88=A0=E9=99=A4>[application.properties?= =?UTF-8?q?]:=20=E5=88=A0=E9=99=A4properties=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=EF=BC=8C=E4=BD=BF=E7=94=A8yml=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application.properties | 11 ----------- src/main/resources/application.yml | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 11 deletions(-) delete mode 100644 src/main/resources/application.properties create mode 100644 src/main/resources/application.yml diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties deleted file mode 100644 index 71cd5e3..0000000 --- a/src/main/resources/application.properties +++ /dev/null @@ -1,11 +0,0 @@ -spring.freemarker.cache=false -spring.freemarker.prefix= -spring.freemarker.suffix=.html -spring.freemarker.enabled=true -spring.freemarker.charset=UTF-8 -spring.freemarker.template-loader-path=classpath:/templates/ -spring.servlet.multipart.max-file-size=100MB -spring.servlet.multipart.max-request-size=1000MB -file.upload.root.dir.windows = C:/work/upload/ -file.upload.root.dir.mac = ~/upload/ -file.upload.root.dir.linux = ~/upload/ \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000..92e68dc --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,19 @@ +spring: + freemarker: + cache: false + charset: UTF-8 + enabled: true + prefix: '' + suffix: .html + template-loader-path: classpath:/templates/ + servlet: + multipart: + max-file-size: 100MB + max-request-size: 1000MB +file: + upload: + root: + dir: + linux: ~/upload/ + mac: /users/gaohanghang/upload/ + windows: C:/work/upload/