Which way of mapping action class to request is recommended?
In struts 2, the action to class mapping can be done in 2 ways:(Please pardon the wrong syntax)
action = "action1" class = "class1" results = "results1"
action = "action2" class = "class2" results = "results2"
and so on for each action = 1 , 2 ....n
i.e. 1 action class per request
Or:
action = "action1" class = "class1" results = "results1" method = "method1"
action = "action2" class = "class1" results = "results1" method = "method2"
and so on. i.e only 1 actio开发者_Python百科n class for all requests. But each action has a separate method.
Is there any best practice which to use when?
Think of it as you would a general Java problem. Should I create a new class to address this issue or should I create a new method to address this issue? That is, is this a new thing or better expressed as a behavior of an existing thing.
If you have a page which will display employees, then that deserves an action class. If you have another page that displays companies, that deserves another action class. I like to put CRUD and certain Ajax features into the same class because I think I move around less that way.
It wouldn't however make sense to have one action class loaded with methods mashing together unrelated ideas, well it wouldn't be Java thinking anyways.
Really one action to one class is a personal preference thing but I think you should be consistent what ever you do. Projects that don't require much crud or ajax perhaps would use methods as actions so rarely that perhaps it would be better to just consistently avoid them.
精彩评论