读书人

spring-mvc属性编辑器绑定跟传文件

发布时间: 2012-10-08 19:54:56 作者: rapoo

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"/>
?

读书人网 >VC/MFC

热点推荐