Spring mvc提交form包含date類型數據錯誤400問題。

在Web項目中提交form提交報400錯誤一般造成的情況是提交參數與接收參數不匹配,但是在spring mvc中出現這種error還可能是參數未作綁定。


具體的解決辦法就是在controller中加入如下代碼:

/**
	 * 數據綁定
	 * 
	 * @param binder
	 *            WebDataBinder
	 */
	@InitBinder
	protected void initBinder(WebDataBinder binder) {
		binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
		binder.registerCustomEditor(Date.class, new DateEditor(true));
	}

一般情況下這個數據會寫在BaseController中,然後所有controller都繼承BaseController

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章