`

spring MVC上传附件和前台提交日期到对象的一个Date类型的参数

阅读更多
一、附件上传,
1、在applicationContext.xml中添加:
<!-- 支持上传文件 --> 
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"></bean>
2、在controller中这样接受:
@RequestMapping("/upload")
public @ResponseBody int uploadExcel(@RequestParam MultipartFile file, Model model){}
3、file与前台的<input type='file' name='file'> name名字必须一样。
二、date参数接受
在controller中添加下面代码:
@InitBinder
public void initBinder(WebDataBinder binder) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
dateFormat.setLenient(false);
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));//true:允许输入空值,false:不能为空值
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics