当要新增或修改的from表单对象中,需要上传额外的附件
public String save(HttpServletRequest request, EvcEnterprisePark evcEnterprisePark, MultipartFile license) {
// 获取文件名称
String licenseFileName = license.getOriginalFilename();
//System.out.println(licenseFileName);
if (licenseFileName != null && !licenseFileName.equals("")) {
// 获取文件扩展名
String extendName = licenseFileName.substring(licenseFileName.lastIndexOf('.'));
// 将文件名称改成以企业命名
String licenseFile = evcEnterprisePark.getEnterpriseParkName() + extendName;
// 定义文件存放路径
ServletContext context = request.getServletContext();
/* E:\work\HZX\svn\dcs-center-web\src\main\webapp */
String basePath = context.getRealPath("/static/evc/license");
try {// 将文件写入到指定位置
license.transferTo(new File(basePath, licenseFile));
evcEnterprisePark.setLicenseFile(licenseFile);
} catch (Exception e) {
e.printStackTrace();
}
}
evcEnterpriseParkService.save(evcEnterprisePark);
return "redirect:"+Global.getAdminPath()+"/evcenterprisepark/evcEnterprisePark/?repage";
}