首先添加lib:
<dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-config-browser-plugin</artifactId> <version>2.3.20</version> </dependency> <dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-convention-plugin</artifactId> <version>2.3.20</version> </dependency>
訪問 http://localhost:8080/conv/config-browser/a.action 可以查看目前映射的所有路徑
插件會按以下順序執(zhí)行:
1.尋找以下包:struts, struts2, action ,actions
任何深度找到的以上包都自動(dòng)作為根目錄
2.然后在包內(nèi)尋找以下類:實(shí)現(xiàn)了com.opensymphony.xwork2.Action或者繼承了com.opensymphony.xwork2.ActionSupport,或類名以Action結(jié)尾
3.映射為url:
com.example.actions.MainAction -> /maincom.example.actions.PRoducts.Display -> /products/displaycom.example.struts.company.details.ShowCompanyDetailsAction -> /company/details/show-company-details(全部為小寫)
比如,
會映射成,

可以跳過某些包:struts.convention.exclude.packages=org.apache.struts.*,org.apache.struts2.*,org.springframework.web.struts.*,org.springframework.web.struts2.*,org.hibernate.* (被跳過的包是無法再加入的,即使手動(dòng)添加)
自動(dòng)搜索的包名:struts.convention.package.locators=action,actions,struts,struts2
自動(dòng)搜索的包名開頭:struts.convention.package.locators.basePackage=
自動(dòng)搜索的類名結(jié)尾:struts.convention.action.suffix=Action
手動(dòng)指定具體包:struts.convention.action.packages=
4.默認(rèn),所有的Result都到這里去找:WEB-INF/content
如,
,則可以通過 http://localhost:8080/conv/my-jsp.action 訪問到
可通過常量控制:struts.convention.result.path=/WEB-INF/content/
根據(jù)返回類型和返回字符串,要起不同的名字:

5.如果找不到這個(gè)頁面文件,就認(rèn)為這是個(gè)action,其他action可以在方法上添加@Action(“xx”),指明具體路徑,這也就是Result Type為chain
如
中,
public class MyJsp extends ActionSupport { public String execute() {return "here"; }}public class HimJsp extends ActionSupport { @Action("my-jsp-here") //通過指定為具體路徑,實(shí)現(xiàn)chain,前提是沒有那個(gè)頁面文件 public String execute() {return "yes"; }}最后會變成,

可以設(shè)置自動(dòng)重載:
<constant name="struts.devMode" value="true"/>
<constant name="struts.convention.classes.reload" value="true" />
struts.convention.action.alwaysMapExecute =false 禁止自動(dòng)調(diào)用execute()
struts.convention.action.disableScanning=true 禁用掃描
struts.convention.action.mapAllMatches =true 沒有@Action也自動(dòng)映射
struts.convention.action.name.lowercase=false 不要變成小寫
struts.convention.action.name.separator=_ 名稱分隔符
struts.convention.action.eagerLoading=true 不使用Spring的時(shí)候可以提高性能
新聞熱點(diǎn)
疑難解答
圖片精選