最近碰到一个问题,在参数里加上Date日期的参数,发现接收不到。在网上查了下相关的资料,发现好多解决方法。
下面是我用的方法:
@InitBinder
protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
CustomDateEditor dateEditor = new CustomDateEditor(format, true);
binder.registerCustomEditor(Date.class, dateEditor);
}
是直接写在Controller里,就行了。