@RequestMapping("/addstandard")
public String addstandard(Standard standard, @RequestParam(“uploadFile”) MultipartFile multipartFile) throws IOException {
//文件名称
String fileName = multipartFile.getOriginalFilename();
//文件后缀名
String suffix = fileName.substring(fileName.lastIndexOf("."));
//文件名
SimpleDateFormat sdf = new SimpleDateFormat(“yyyyMMddhhmmssSSS”);
String newFileName = sdf.format(new Date())+suffix;
//获取当前项目的类路径
String classPath = ResourceUtils.getURL(ResourceUtils.CLASSPATH_URL_PREFIX).getPath();
System.out.println(“类路径:”+classPath);
File file = new File(classPath+path);
if(!file.exists()){
file.mkdirs();
}
//文件归档
multipartFile.transferTo(new File(file.getAbsolutePath()+File.separator+newFileName));
standard.setPackagepath(newFileName);
standardService.saveStandard(standard);
return "redirect:/list";
}