@RequestMapping("/updateUpload1")
public ModelAndView updateUpload1(MultipartFile file, String id,
String inspect_id) {
Map<String, Object> map = new HashMap<String, Object>();
PageData pd = new PageData();
try {
pd = this.getPageData();
String filename = null;
if (Jurisdiction.buttonJurisdiction(menuUrl, "add")) {
if (null != file && !file.isEmpty()) {
// 上传路径
String path = "C:/inspect";
// 文件名
filename = file.getOriginalFilename();
File filePath = new File(path, filename);
// 判断路径是否存在, 不存在就重新建一个
if (!filePath.getParentFile().exists()) {
filePath.getParentFile().mkdirs();
}
file.transferTo(new File(path + File.separator + filename));
} else {
System.out.println("上传失败");
}
}
map.put("result", "ok");
} catch (Exception e) {
map.put("result", "no");
logger.error(e.toString(), e);
}
return new ModelAndView("save_result");
}
@RequestMapping(value = "/download1")
public void downDocument1(HttpServletRequest request, HttpServletResponse response) throws Exception {
// 获取文件下载路径
//String filePath = PathUtil.getClasspath() + Const.INSPECTFILEPATHIMG + time + File.separator + inspect_document; //文件上传路径
String path = "C:/inspect/";
PageData pageData = new PageData();
pageData = this.getPageData();
//获取信息
PageData data = inspectOrderService.findById(pageData);
//文件名
String filename = data.getString("inspect_document");
String[] strs = filename.split("[.]");
//截取最后文件属性
String name = strs[strs.length - 1];
File file = new File(path + filename);
String time = data.getString("inspect_document_time").replaceAll("-", "");
if (file.exists()) {
// 设置相应类型application/octet-stream
response.setContentType("application/x-msdownload");
// 设置头信息
response.setHeader("Content-Disposition", "attachment;filename=\"" + time + "." + name + "\"");
InputStream inputStream = new FileInputStream(file);
ServletOutputStream ouputStream = response.getOutputStream();
byte b[] = new byte[1024];
int n;
while ((n = inputStream.read(b)) != -1) {
ouputStream.write(b, 0, n);
}
// 关闭流、释放资源
ouputStream.close();
inputStream.close();
}
}