SpringMVC日期類型轉換問題三大處理方法概括

http://blog.csdn.net/chenleixing/article/details/45190371測試

 

 

方法一:實體類中加日期格式化註解

 

  1. @DateTimeFormat(pattern = "yyyy-MM-dd")  
  2. private Date receiveAppTime;  

如上,在對應的屬性上,加上指定日期格式的註解,本人親自測試過,輕鬆解決問題!spa

 

方法二:控制器Action中加入一段數據綁定代碼

 

  1. @InitBinder  
  2. public void initBinder(WebDataBinder binder) {  
  3. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");  
  4. dateFormat.setLenient(false);  
  5. binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));   //true:容許輸入空值,false:不能爲空值  
相關文章
相關標籤/搜索