@InitBinder 用法

来源:[url]
http://yeak2001.iteye.com/blog/465325
[/url]




@Controller  
public class MyFormController {   
  
    @InitBinder  
    public void initBinder(WebDataBinder binder) {   
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");   
        dateFormat.setLenient(false);   
        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));   
    }   
  
    // ...   
}  
WebDataBinder是用来绑定请求参数到指定的属性编辑器,可以继承WebBindingInitializer来实现一个全部controller共享的dataBiner 
Java代码  
@Component  
public class CommonBindingInitializer implements WebBindingInitializer {   
  
    public void initBinder(WebDataBinder binder, WebRequest request) {   
        SimpleDateFormat dateFormat = new SimpleDateFormat(ERPUtil.ISO_DATE_MASK);   
        dateFormat.setLenient(false);   
        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));   
        binder.registerCustomEditor(String.class, new StringTrimmerEditor(false));   
    }   
} 


你可能感兴趣的:(InitBinder)