Bladeren bron

设备器材导入

gaodandan 5 jaren geleden
bovenliggende
commit
a231f4aa66

+ 4 - 1
src/main/java/com/chinaitop/depot/device/controller/BasicEquipmentEquipmentPoolController.java

@@ -9,6 +9,7 @@ import java.util.Map;
9 9
 import javax.annotation.Resource;
10 10
 import javax.servlet.http.HttpServletRequest;
11 11
 
12
+import org.springframework.beans.factory.annotation.Value;
12 13
 import org.springframework.http.MediaType;
13 14
 import org.springframework.web.bind.annotation.RequestMapping;
14 15
 import org.springframework.web.bind.annotation.RequestMethod;
@@ -42,6 +43,8 @@ public class BasicEquipmentEquipmentPoolController {
42 43
 	private BasicEquipmentEquipmentPoolService poolServivce;
43 44
 	@Resource
44 45
 	private ImportServiceImpl importService;
46
+	@Value("${web.upload-path}")
47
+	private String uploadPath;
45 48
 
46 49
 	/**
47 50
 	 * 查询数据列表
@@ -183,7 +186,7 @@ public class BasicEquipmentEquipmentPoolController {
183 186
         List<List<String>> list = new ArrayList<List<String>>();//该list为数据返回的list
184 187
         String errormsg = null;
185 188
         try {
186
-        	errormsg = importService.importFile(file, fileType, request, titleArr, emptyArr, list);
189
+        	errormsg = importService.importFile(uploadPath,file, fileType, request, titleArr, emptyArr, list);
187 190
         	
188 191
         	if (errormsg != null && !"".equals(errormsg)) {
189 192
         		return errormsg;

+ 11 - 11
src/main/java/com/chinaitop/depot/device/service/impl/ImportServiceImpl.java

@@ -31,20 +31,20 @@ public class ImportServiceImpl {
31 31
 
32 32
 
33 33
 
34
-    public String importFile(MultipartFile file, String fileType, HttpServletRequest request,String[] titleArr,boolean[] emptyArr,List<List<String>> lists) throws Exception{
34
+    public String importFile(String uploadPath,MultipartFile file, String fileType, HttpServletRequest request,String[] titleArr,boolean[] emptyArr,List<List<String>> lists) throws Exception{
35 35
 
36
-        // 服务器路径
37
-        String rootPath = request.getSession().getServletContext().getRealPath("");
38
-        // 文件相对路径
39
-        String relativePath = "/upload/" + fileType;
40
-        //创建临时文件
41
-        createTemp(file,request,rootPath,relativePath);
42
-        //读取临时文件,并且返回错误信息
43
-        String fileAllpath = rootPath+relativePath+"/"+file.getOriginalFilename();
36
+    	// 服务器路径
37
+       //      String rootPath = request.getSession().getServletContext().getRealPath("");
38
+      // 文件相对路径
39
+      String relativePath = "/upload/" + fileType;
40
+      //创建临时文件
41
+      createTemp(file,request,uploadPath,relativePath);
42
+      //读取临时文件,并且返回错误信息
43
+      String fileAllpath = uploadPath+relativePath+"/"+file.getOriginalFilename();
44 44
 
45
-        String retVal = readExcelValue(fileAllpath,titleArr,emptyArr,lists);
45
+      String retVal = readExcelValue(fileAllpath,titleArr,emptyArr,lists);
46 46
 
47
-        return retVal;
47
+      return retVal;
48 48
     }
49 49
 
50 50
     /**