@InitBinder 
  在controller中注册一个customer protperty editor以解析request中的参数并通过date bind机制与handler method中的参数做绑定。 

@InitBinder
public void initBinder(WebDataBinder binder) {
       SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
       dateFormat.setLenient(false);
       binder.registerCustomEditor(Date.class, new CustomDateEditor(
              dateFormat, false));
}

Handler method代码如下

   @RequestMapping("/databind")
    public ModelAndView databind1(Date date) {
      …   
   }

访问url http://localhost:8080/springmvc/databind?date=2000-01-02 
通过initbinder中注册的customeDateEditor类型,自动将2000-01-02转换为日期类型 

 

相关文章:

  • 2022-01-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-27
  • 2021-10-15
  • 2022-12-23
猜你喜欢
  • 2021-11-21
  • 2021-11-05
  • 2022-12-23
  • 2021-10-31
  • 2021-09-21
  • 2022-01-16
  • 2021-06-04
相关资源
相似解决方案