示例代码
@Controller
@RequestMapping("/data_configs")
public class DataConfigController {
@InitBinder//org.springframework.web.bind.annotation.InitBinder;
public void test(ServletRequestDataBinder binder){
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
binder.registerCustomEditor(Timestamp.class, new CustomDateEditor(dateFormat, true));
}
@RequestMapping("")
public ModelAndView index(Timestamp date,ModelAndView result){
System.out.println("-----------"+date);
return result;
}
}
测试结果
访问**/data_configs?date=2018-3-15 12:16:00
程序输出的结果是:-----------2018-03-15 12:16:00.0