读书人

struts2 convention plugin札记

发布时间: 2012-08-31 12:55:03 作者: rapoo

struts2 convention plugin笔记

?

?

要保证Conventtion plugin可以找到我们的action类。默认情况下,Convention plugin将找到所有的action类,当然前提是,这个些类已经实现了(implement) com.opensymphony.xwork2.Action接口,或者这些类得名字以Action结尾,并且这些类存放的特定包名,包名中必须包含这些中的一个 struts, struts2, action or actions。

例如:

action类得名字以Action结尾

com.example.actions.MainAction

action类实现了com.opensymphony.xwork2.Action接口

com.example.actions.products.Display (implements com.opensymphony.xwork2.Action)

action类名字以Action结尾。

com.example.struts.company.details.ShowCompanyDetailsAction

以上的action类都可以被convention plugin所找到。

?

注意:

如果没有implements com.opensymphony.xwork2.Action 并且没有 extends com.opensymphony.xwork2.ActionSupport的情况下必须要有execute()方法,否则扫描不到

----------------------------------------------

这些action类的命名空间如下所示(每个action,配置时候都会有命名空间namespace,如果不配置则命名空间为/)

com.example.actions.MainAction -> /

com.example.actions.products.Display -> /products

com.example.struts.company.details.ShowCompanyDetailsAction -> /company/details

URL规则是以struts, struts2, action or actions 为基础的。

-----------------------------------------------

在浏览器访问action的URL如下所示

com.example.actions.MainAction -> /main

com.example.actions.products.Display -> /products/display

com.example.struts.company.details.ShowCompanyDetailsAction -> /company/details/show-company-details

URL规则是,如果以Action结尾的action类,URL就是为类的首字母变为小写,然后后面的其他的首字母也小写单词都以“-”隔开

---------------------

?

?

无聊翻出笔记,贴上来

?

读书人网 >编程

热点推荐