Is it best practice to map multiple actions to the same class struts 2.3 [closed]

六眼飞鱼酱① 提交于 2019-11-26 18:37:00

问题


I am developing contact manager in struts with options(add,delete,modify,print).

I am thinking to map multiple actions(map multiple actions to the same class struts 2.3) to the same class(ContactManager).

I want to know whether it is correct or whether there is need to write separate action for each action?


回答1:


One good way to go, imho , is to use one Action for every action you have to perform, each one extending its last-forked parent Actions, like:

BaseAction
|
|----------BaseReportAction
|          |----- ExcelReportAction
|          |----- PDFReportAction
|          |----- CSVReportAction
|
|
|----------BaseCRUDAction
|          |----- CreateAction
|          |----- ReadAction
|          |----- UpdateAction
|          |----- DeleteAction
|
|
|----------BaseAJAXAction
|          |----- ReadSessionCountdownAction
|          |----- CheckNewMailsAction
|

etc...

Every Action extended by others will share protected attributes / methods to the children.

Take a look at this: Changing parameters after bind in Struts 2

My 2 cents.




回答2:


I think you should use a single action. It is totally a good practice, after all they provided the facility to invoke different methods in the same Action class for a purpose! You can achieve something like this by including a wildcard which which can map your action name to appropriate method in Action class.Like this-

    <action name="abc*" method="{1}" />


来源:https://stackoverflow.com/questions/13510196/is-it-best-practice-to-map-multiple-actions-to-the-same-class-struts-2-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!