@ResponseBody
@RequestMapping(value="ajaxFileUpload",method = {RequestMethod.POST,RequestMethod.GET})
public String ajaxFileUpload(Model model,HttpServletResponse response, @RequestParam MultipartFile myfile,HttpServletRequest request){
BCaseReltiveAttachment bCaseReltiveAttachment = new BCaseReltiveAttachment();
Map<String,Object> map= new HashMap<String,Object>();
if(myfile.isEmpty()){
map.put( "result", "error");
map.put( "data", bCaseReltiveAttachment);
String time1=format1.format(date1);
String changeFileName = time+houzhui; //磁盘存储后的文件名
//获取文档类型
String path = tAssesssmentFilePathService.findPathByType(frimType);
String type = dictService.getLabelByTypeAndValue("wdlx", frimType);
try{
//把附件放到指定目录下
//保存附件信息到,附件信息记录表 此操作可忽略,将文件信息存放在文件表中
bCaseReltiveAttachment = bCaseReltiveAttachmentService.saveReltiveAttachments2(type,tableName,originalFilename,currentUser,genePicPath+changeFileName);
//返回页面,附件信息数据
map.put( "result", "success");
map.put( "data", bCaseReltiveAttachment);
//jsonStrAttachment=JsonMapper.toJsonString(bCaseReltiveAttachment);
} catch (Exception e) {
e.printStackTrace();
map.put( "result", "error");
map.put( "msg",e.getMessage());
}
}
String ret = JsonMapper.toJsonString(map);
return ret;
}
@RequestMapping(value="ajaxFileUpload",method = {RequestMethod.POST,RequestMethod.GET})
public String ajaxFileUpload(Model model,HttpServletResponse response, @RequestParam MultipartFile myfile,HttpServletRequest request){
BCaseReltiveAttachment bCaseReltiveAttachment = new BCaseReltiveAttachment();
Map<String,Object> map= new HashMap<String,Object>();
if(myfile.isEmpty()){
map.put( "result", "error");
map.put( "data", bCaseReltiveAttachment);
} else{
// 在后台加密,让文件名以时间命名
Date date=new Date();DateFormat format=new SimpleDateFormat("yyyyMMddHHmmss");
String time=format.format(date);
//把文件存放在以时间分开的文件夹内
Date date1=new Date();
DateFormat format1=new SimpleDateFormat("yyyy-MM-dd");String time1=format1.format(date1);
String originalFilename=myfile.getOriginalFilename(); //真实文件名
String houzhui = originalFilename.substring(originalFilename.lastIndexOf("."), originalFilename.length());String changeFileName = time+houzhui; //磁盘存储后的文件名
//获取文档类型
String path = tAssesssmentFilePathService.findPathByType(frimType);
String type = dictService.getLabelByTypeAndValue("wdlx", frimType);
try{
//把附件放到指定目录下
String genePicPath = "D:/jeesiteFiles/userfiles/1/files/"+path+"/"+time1+"/";
//上传文件
FileUtils. copyInputStreamToFile(myfile.getInputStream(), new File(genePicPath,changeFileName));//保存附件信息到,附件信息记录表 此操作可忽略,将文件信息存放在文件表中
bCaseReltiveAttachment = bCaseReltiveAttachmentService.saveReltiveAttachments2(type,tableName,originalFilename,currentUser,genePicPath+changeFileName);
//返回页面,附件信息数据
map.put( "result", "success");
map.put( "data", bCaseReltiveAttachment);
//jsonStrAttachment=JsonMapper.toJsonString(bCaseReltiveAttachment);
} catch (Exception e) {
e.printStackTrace();
map.put( "result", "error");
map.put( "msg",e.getMessage());
}
}
String ret = JsonMapper.toJsonString(map);
return ret;
}