先來看看Spring中的Controller繼承關係
在BaseCommandController中提供了數據綁定的功能。
數據綁定,你可以理解爲將表單中的數據,自動綁定到對應的Controller中對應的對象中,不用自己通過request.getParameter(String)方法來得到請求中的參數。再轉換類型綁定到對應的屬性,
SimpleFormController可以理解爲專門爲表單提交設計的Controller類
public class User(){
private String userName;
private String userAge;
/*
setter,getter方法
*/
}
<form action="*.do" method="post">
<input type="text" name="userName" />
<input type="text" name="userAge" />
</form>
將表單中的字段按照“name”屬性自動綁定到Controller中的User中,要實現這個功能,BaseCommandController需要有一個對象,來充當這個“User”,BaseCommandController中用“Command”來代表這個對象。
說的不好 ,來看看Spring官方提供的解釋:
百度翻譯。。。。
意思就是這麼個意思,下面我們來看看繼承了BaseFormController的SimpleFormController怎麼來處理表單提交後的流程的
(其實如果我們要用Spring的數據綁定功能(個人感覺不太喜歡,原理還是有些沒弄懂啊 o.o),最多的應該還是SimpleFormController):
今晚有事,先保存,明天更新