Эх сурвалжийг харах

通过类型添加对应的ContentType

DESKTOP-2K9OVK9\siwei 4 сар өмнө
parent
commit
23fe6f076c

+ 12 - 7
onemap-modules/onemap-analyse/src/main/java/com/onemap/analyse/controller/FzssController.java

@@ -16,6 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.bind.annotation.*;
 
 
+import javax.activation.MimetypesFileTypeMap;
 import javax.annotation.Resource;
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpServletResponse;
 import java.awt.*;
 import java.awt.*;
@@ -48,13 +49,13 @@ public class FzssController extends BaseController {
     public RequestResult AddFzxz(@RequestBody SelectPilotVo selectPilotVo) throws JsonProcessingException {
     public RequestResult AddFzxz(@RequestBody SelectPilotVo selectPilotVo) throws JsonProcessingException {
         if (selectPilotVo.getYdmjbegin() != null) {
         if (selectPilotVo.getYdmjbegin() != null) {
             selectPilotVo.setYdmjbegin((float) (UnitsUtil.muToM2(selectPilotVo.getYdmjbegin())));
             selectPilotVo.setYdmjbegin((float) (UnitsUtil.muToM2(selectPilotVo.getYdmjbegin())));
-        }else{
-            selectPilotVo.setYdmjbegin((float)UnitsUtil.muToM2(10f));
+        } else {
+            selectPilotVo.setYdmjbegin((float) UnitsUtil.muToM2(10f));
         }
         }
         if (selectPilotVo.getYdmjend() != null) {
         if (selectPilotVo.getYdmjend() != null) {
             selectPilotVo.setYdmjend((float) (UnitsUtil.muToM2(selectPilotVo.getYdmjend())));
             selectPilotVo.setYdmjend((float) (UnitsUtil.muToM2(selectPilotVo.getYdmjend())));
-        }else{
-            selectPilotVo.setYdmjend((float)UnitsUtil.muToM2(100f));
+        } else {
+            selectPilotVo.setYdmjend((float) UnitsUtil.muToM2(100f));
         }
         }
 
 
         // 存储规划参数
         // 存储规划参数
@@ -127,9 +128,14 @@ public class FzssController extends BaseController {
         if ("zip".equals(extension)) {
         if ("zip".equals(extension)) {
             DownloadUtils.download(response, realFileName, null);
             DownloadUtils.download(response, realFileName, null);
         } else {
         } else {
+            // 建议定义为静态常量,可复用
+            MimetypesFileTypeMap mimeTypeMap = new MimetypesFileTypeMap();
+            // 传入文件名,得到文件类型,判断失败则返回application/octet-stream
+            String contentType = mimeTypeMap.getContentType(downloadName.substring(lastIndex));
             response.setCharacterEncoding("utf-8");
             response.setCharacterEncoding("utf-8");
-            response.setContentType("multipart/form-data");
-            response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
+            response.setContentType(contentType);
+//            response.setContentType("multipart/form-data");
+//            response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
             response.setHeader("Content-Disposition", "attachment;fileName=" + URLEncoder.encode(downloadName, "UTF-8"));
             response.setHeader("Content-Disposition", "attachment;fileName=" + URLEncoder.encode(downloadName, "UTF-8"));
             FileUtils.writeBytes(realFileName, response.getOutputStream());
             FileUtils.writeBytes(realFileName, response.getOutputStream());
         }
         }
@@ -152,7 +158,6 @@ public class FzssController extends BaseController {
     public RequestResult openFile(String filePath) throws IOException {
     public RequestResult openFile(String filePath) throws IOException {
 
 
 
 
-
         File file = new File(filePath);
         File file = new File(filePath);
 
 
         try {
         try {