spring-mvc属性编辑器绑定和传文件
?
@InitBinderpublic void initBinder(WebDataBinder binder) {// 忽略字段绑定异常binder.setIgnoreInvalidFields(true);DateFormat format = new SimpleDateFormat("yyyy-MM-dd");binder.registerCustomEditor(Date.class, "buyDate",new CustomDateEditor(format, true));binder.registerCustomEditor(Date.class, "brPhoneDate",new CustomDateEditor(format, true));binder.registerCustomEditor(Date.class, "brDate",new CustomDateEditor(format, true));}
?// 通过excel导入手机卡数据
?
@RequestMapping(value = "phone/excel/input.do")public ModelAndView upload(@RequestParam(value = "file", required = false) MultipartFile file) {try {if (file != null)this.phoneService.addByExcel(file.getInputStream());return new ModelAndView("redirect:/phones.do");} catch (Exception e) {e.printStackTrace();return new ModelAndView("error", "message", "导入数据失败");}}
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/>?