@RequestMapping(value = "/addSubProject",method = RequestMethod.POST,produces=MediaType.APPLICATION_JSON_VALUE)
public ModelAndView addSubProject(@ModelAttribute("subProject") SubProject subProject,@RequestParam("file") MultipartFile[] files,HttpServletRequest request,HttpServletResponse response,@RequestParam("subPid") Long subPid){
try {
String path=null;
String fileName=null;
StringBuffer sb = new StringBuffer();
for (MultipartFile multipartFile : files) {
if (multipartFile == null || multipartFile.isEmpty()) {
continue;
}
//String rootPath = request.getServletContext().getRealPath("/");
//fileName = new String(multipartFile.getOriginalFilename().getBytes("ISO8859-1"), "UTF-8");
path = FileOperateUtil.UPLOADDIR_SUPPROJECT;
fileName = path+multipartFile.getOriginalFilename();
File targetFile = new File(path);
if (!targetFile.exists()) {
targetFile.mkdirs();
}
byte[] bytes = multipartFile.getBytes();
BufferedOutputStream buffStream = new BufferedOutputStream(new FileOutputStream(fileName));
buffStream.write(bytes);
buffStream.close();
sb.append(fileName + ";");
}
if (subPid!=null) {
subProject.setPath(sb.toString());
subProjectService.updateSubProjectInfo(subProject,subPid);
}else{
subProject.setPath(sb.toString());
subProjectService.addSubProject(subProject);
}
} catch (BusinessServiceException e) {
logger.error(e.getMessage());
}catch (Exception e) {
logger.error(e.getMessage());
throw new RestException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage());
}
//使用ModelAndView重定向到查询列表
//return new ModelAndView("redirect:/"+AppModule.SUBPROJECT_MANAGE_EN);
return new ModelAndView("redirect:/"+AppModule.ATTACHMENT_UPLOAD_EN);
}
public ModelAndView addSubProject(@ModelAttribute("subProject") SubProject subProject,@RequestParam("file") MultipartFile[] files,HttpServletRequest request,HttpServletResponse response,@RequestParam("subPid") Long subPid){
try {
String path=null;
String fileName=null;
StringBuffer sb = new StringBuffer();
for (MultipartFile multipartFile : files) {
if (multipartFile == null || multipartFile.isEmpty()) {
continue;
}
//String rootPath = request.getServletContext().getRealPath("/");
//fileName = new String(multipartFile.getOriginalFilename().getBytes("ISO8859-1"), "UTF-8");
path = FileOperateUtil.UPLOADDIR_SUPPROJECT;
fileName = path+multipartFile.getOriginalFilename();
File targetFile = new File(path);
if (!targetFile.exists()) {
targetFile.mkdirs();
}
byte[] bytes = multipartFile.getBytes();
BufferedOutputStream buffStream = new BufferedOutputStream(new FileOutputStream(fileName));
buffStream.write(bytes);
buffStream.close();
sb.append(fileName + ";");
}
if (subPid!=null) {
subProject.setPath(sb.toString());
subProjectService.updateSubProjectInfo(subProject,subPid);
}else{
subProject.setPath(sb.toString());
subProjectService.addSubProject(subProject);
}
} catch (BusinessServiceException e) {
logger.error(e.getMessage());
}catch (Exception e) {
logger.error(e.getMessage());
throw new RestException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage());
}
//使用ModelAndView重定向到查询列表
//return new ModelAndView("redirect:/"+AppModule.SUBPROJECT_MANAGE_EN);
return new ModelAndView("redirect:/"+AppModule.ATTACHMENT_UPLOAD_EN);
}