springmvc后台用date类型接受前台参数时,一直报错
springmvc后台用date类型接受前台参数时,一直报错:Failed to load resource: the server responded with a status of 400 (Bad Request)

spring mvc 后台只接收String类型,所以需要对日期类型处理
一、只需要在方法中加入
- @InitBinder
- protected void initBinder(WebDataBinder binder) {
- SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
- binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
- }
方法就可以
二、注解方式:
- @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8") //取日期时使用
- @DateTimeFormat(pattern = "yyyy-MM-dd")//存日期时使用
- private Date startTime;

转发自:http://blog.csdn.net/jiana227/article/details/18663159
浙公网安备 33010602011771号