Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 保存在文件夹中的附件与保存在不同文件夹中的其他附件混合_Java_Spring Mvc - Fatal编程技术网

Java 保存在文件夹中的附件与保存在不同文件夹中的其他附件混合

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

因此,我的项目包括为每个生成的请求生成一个唯一的请求id的工作流,例如生成FAF/2020-21/0253,在服务器上提到的路径上创建名为0253的文件夹,并以格式保存附件,例如(ISAMEA Certificate print_Req_576_010720_111908.xlsx) 有时,保存在一个文件夹上的附件也会添加到另一个文件夹中

private void uploadAttachmentToDiskAttach(财务ApprovalBean fab、字符串GenetareId、字符串strLoginUserId、, 字符串(角色){

`保存附件的服务器上的路径`
字符串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**