Struts和SpringMVC傳遞引數比較

2021-09-29 10:08:41 字數 1362 閱讀 3017

struts和springmvc預設均是使用的請求**進行引數傳遞

jsp**:

1.jsp

2.jsp

1、方法引數直接傳遞

public string demo02(string username,string password)

2、方法物件傳遞時,1.jsp和2.jsp均可(與struts的強制要求不同)

public string demo02(user user)

3、model傳遞

public string demo04(model model,user user)

1、基本引數屬性傳遞

在action中設定相關屬性,預設和請求傳遞引數名相同,使用set方法對相關屬性進行設值

action**:

public class demoaction 

public void setusername(string username)

public string getpassword()

public void setpassword(string password)

public string login()

}

jsp**:

2、物件屬性傳遞

在action中設定相關物件屬性,預設物件屬性和請求傳遞引數名(物件名.屬性名)必須對應(請求引數名不能直接是物件的屬性,需要主動實現型別轉換器,此處和springmvc不同),使用set方法對相關屬性進行設值

action**:

public class formaction

public void setuser(user user)

public string login()

}

jsp**:

3、action實現modeldriven介面傳遞,需要實現getmodel()方法

action**:

public class formaction implements modeldriven

public void setuser(user user)

public string login()

@override

public user getmodel()

}

jsp**:

SpringBoot擴充套件SpringMVC

編寫乙個配置類,型別是webmvcconfigureradapter 繼承 使用webmvcconfigureradapter可以擴充套件,不能標註 enablewebmvc 既保留了配置,也能拓展我們自己的應用 configuration public class mymvcconfig exte...

springMVC學習(一)springMVC簡介

springmvc介紹 spring web mvc和struts2都屬於表現層的框架,它是spring框架的一部分,我們可以從spring的整體結構中看得出來 spring的整體結構圖 mvc是一種設計模式,mvc在b s系統下的應用 理解 1 使用者發起request請求至控制器 control...

Thymeleaf模板與Spring MVC整合

thymeleaf 定義了 org.thymeleaf.spring4.view.thymeleafview 和 org.thymeleaf.spring4.view.thymeleafviewresolver 預設使用thymeleafview 作為 view thymeleaf 提供了乙個spr...