作者 朱兆平

文件上传配置及静态目录配置修改

@@ -7,8 +7,6 @@ readDirectory = /Users/mrz/Documents/java项目/test @@ -7,8 +7,6 @@ readDirectory = /Users/mrz/Documents/java项目/test
7 #接收存储报文目录 7 #接收存储报文目录
8 bakDirectory = kakoRevice 8 bakDirectory = kakoRevice
9 #是否需要发送报文,默认N不发,Y将发送readDirectory下的XML扩展名的报文 9 #是否需要发送报文,默认N不发,Y将发送readDirectory下的XML扩展名的报文
10 -#上传文件路径,必填  
11 -uploadDirectory = upload  
12 isNeedSend = Y 10 isNeedSend = Y
13 11
14 #IMF MEAT报头配置 12 #IMF MEAT报头配置
@@ -22,4 +22,4 @@ @@ -22,4 +22,4 @@
22 * 集成websocket 22 * 集成websocket
23 * 集成lombok,简化部分代码录入,比如实体类,方便实体及表结构修改,敏捷开发必用,使用方法见[lombok集成使用说明](https://jingyan.baidu.com/article/0a52e3f4e53ca1bf63ed725c.html) 23 * 集成lombok,简化部分代码录入,比如实体类,方便实体及表结构修改,敏捷开发必用,使用方法见[lombok集成使用说明](https://jingyan.baidu.com/article/0a52e3f4e53ca1bf63ed725c.html)
24 ) 24 )
25 - 25 +* 集成了单文件、多文件上传接口
@@ -7,6 +7,7 @@ import com.tianbo.warehouse.util.Date.DateUtil; @@ -7,6 +7,7 @@ import com.tianbo.warehouse.util.Date.DateUtil;
7 import com.tianbo.warehouse.util.Helper; 7 import com.tianbo.warehouse.util.Helper;
8 import org.apache.commons.io.FileUtils; 8 import org.apache.commons.io.FileUtils;
9 import org.springframework.beans.factory.annotation.Autowired; 9 import org.springframework.beans.factory.annotation.Autowired;
  10 +import org.springframework.beans.factory.annotation.Value;
10 import org.springframework.web.bind.annotation.PostMapping; 11 import org.springframework.web.bind.annotation.PostMapping;
11 import org.springframework.web.bind.annotation.RequestParam; 12 import org.springframework.web.bind.annotation.RequestParam;
12 import org.springframework.web.bind.annotation.RestController; 13 import org.springframework.web.bind.annotation.RestController;
@@ -23,6 +24,8 @@ public class UploadController { @@ -23,6 +24,8 @@ public class UploadController {
23 @Autowired 24 @Autowired
24 private AttachmentService attachmentService; 25 private AttachmentService attachmentService;
25 26
  27 + @Value("${web.upload-path}")
  28 + private String uploadPath; // =./upload/
26 /** 29 /**
27 * 单个文件上传 30 * 单个文件上传
28 * @param file 31 * @param file
@@ -37,9 +40,8 @@ public class UploadController { @@ -37,9 +40,8 @@ public class UploadController {
37 String fileLitleName = file.getName(); 40 String fileLitleName = file.getName();
38 String fileName = file.getOriginalFilename(); 41 String fileName = file.getOriginalFilename();
39 String fileType = fileName.substring((fileName.lastIndexOf("."))); 42 String fileType = fileName.substring((fileName.lastIndexOf(".")));
40 - String saveDir = readProperties("uploadDirectory");  
41 StringBuffer stringBuffer = new StringBuffer(); 43 StringBuffer stringBuffer = new StringBuffer();
42 - String saveFileName = stringBuffer.append(saveDir).append("/").append(DateUtil.getToday()).append("/").append(Helper.getUUID()).append(fileType).toString(); 44 + String saveFileName = stringBuffer.append(uploadPath).append(DateUtil.getToday()).append("/").append(Helper.getUUID()).append(fileType).toString();
43 File saveFile = new File(saveFileName); 45 File saveFile = new File(saveFileName);
44 if(!saveFile.getParentFile().exists()){ 46 if(!saveFile.getParentFile().exists()){
45 saveFile.mkdirs(); 47 saveFile.mkdirs();
@@ -3,6 +3,13 @@ @@ -3,6 +3,13 @@
3 server.port=7003 3 server.port=7003
4 server.servlet.context-path=${SERVER_CONTEXTPATH:} 4 server.servlet.context-path=${SERVER_CONTEXTPATH:}
5 5
  6 +#静态资源,设置上传文件的访问,上传文件的路径,要带斜杠
  7 +web.upload-path=upload/
  8 +#表示所有的访问经过静态资源路径
  9 +springboot.mvc.static-path-pattern=/**
  10 +spring.resources.static-locations=classpath:/META-INF/resources/,classpath:/static,classpath:/resources/,file:${web.upload-path}
  11 +
  12 +
6 13
7 #服务名 14 #服务名
8 spring.application.name=tianbo.base.dev.devkit 15 spring.application.name=tianbo.base.dev.devkit
@@ -6,7 +6,8 @@ import org.springframework.boot.test.context.SpringBootTest; @@ -6,7 +6,8 @@ import org.springframework.boot.test.context.SpringBootTest;
6 import org.springframework.test.context.junit4.SpringRunner; 6 import org.springframework.test.context.junit4.SpringRunner;
7 7
8 @RunWith(SpringRunner.class) 8 @RunWith(SpringRunner.class)
9 -@SpringBootTest 9 +//解决mvn clean package打包项目websocketjavax.websocket.server.ServerContainer not available报错的问题
  10 +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
10 public class WarehouseApplicationTests { 11 public class WarehouseApplicationTests {
11 12
12 @Test 13 @Test