前言
- 最近有一个使用
GET
方式传递参数的需求,在传递时间时突然遇到问题,GET方式接收到的参数是字符串,无法转换为对应的时间,而在平时我们都是使用JSON
来传递参数,可以利用jackson
或者fastjson
来处理,但是queryParams
是不行的.
解决方案
在需要使用GET方式传参的Controller中加上下面的方法即可.
@InitBinder
public void initBinder(WebDataBinder binder) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
dateFormat.setLenient(false);
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
}
Q.E.D.
Comments | 0 条评论