Java 保存在文件夹中的附件与保存在不同文件夹中的其他附件混合
因此,我的项目包括为每个生成的请求生成一个唯一的请求id的工作流,例如生成FAF/2020-21/0253,在服务器上提到的路径上创建名为0253的文件夹,并以格式保存附件,例如(ISAMEA Certificate print_Req_576_010720_111908.xlsx) 有时,保存在一个文件夹上的附件也会添加到另一个文件夹中 private void uploadAttachmentToDiskAttach(财务ApprovalBean fab、字符串GenetareId、字符串strLoginUserId、, 字符串(角色){Java 保存在文件夹中的附件与保存在不同文件夹中的其他附件混合,java,spring-mvc,Java,Spring Mvc,因此,我的项目包括为每个生成的请求生成一个唯一的请求id的工作流,例如生成FAF/2020-21/0253,在服务器上提到的路径上创建名为0253的文件夹,并以格式保存附件,例如(ISAMEA Certificate print_Req_576_010720_111908.xlsx) 有时,保存在一个文件夹上的附件也会添加到另一个文件夹中 private void uploadAttachmentToDiskAttach(财务ApprovalBean fab、字符串GenetareId、字符串s
`保存附件的服务器上的路径`
字符串rootPath=“/data/PamGreenSource/Documents/”+genetaredId;
FinancialAttachmentBean fabc=新的FinancialAttachmentBean();
/*文档=新文档()*/
如果(fab.getFab().size()>0){
对于(int i=0;i
`path on server where attachment is getting saved`
String rootPath = "/data/PamGreenSource/Documents/" + genetaredId;
FinancialAttachmentBean fabc = new FinancialAttachmentBean();
/*Documents document = new Documents();*/
if ( fab.getFab().size() > 0) {
for (int i=0;i<fab.getFab().size();i++) {
if (fab.getFab().get(i).getFiles() != null) {
String orgName = fab.getFab().get(i).getFiles().getOriginalFilename();
File theDir = new File(rootPath);
if (!theDir.exists()) {
boolean result = false;
try {
theDir.mkdirs();
result = true;
} catch (SecurityException se) {
}
if (result) {
}
}
String timestamp = new SimpleDateFormat("ddMMyy_Hmmss").format(new Date());
String fileNameWithOutExt = FilenameUtils.removeExtension(orgName);
if (fileNameWithOutExt != null && !fileNameWithOutExt.isEmpty()) {
fileNameWithOutExt = fileNameWithOutExt + "_" + role + "_" + strLoginUserId + "_" + timestamp;
String extension = FilenameUtils.getExtension(orgName);
fab.getFab().get(i).setAttach_id(fileNameWithOutExt+"."+extension);
String filePath = rootPath + "/" + fileNameWithOutExt + "." + extension;
File dest = new File(filePath);
try {
fab.getFab().get(i).getFiles().transferTo(dest);
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
}**strong text**