问题
I'm working on Struts web based application where I have created an action class with multiple methods in it. I invoke these methods based on the kind of task I want the application to perform. Could someone please tell me if I should use this technique to do so?
Should I continue invoking the methods like I am or should I create separate action classes for every different action I want to perform?
回答1:
One action class can have many actions, many methods, but you should map only one method to the action.
Also note: in the recent releases DMI (Dynamic Method Invocation) is turned off by default and might not work in the future.
It's unclear how do you invoke methods, some interceptors still evolve a method filtering, where you can restrict some methods. But there's no restriction to map different actions in the same action class. And there's no restriction to invoke any action class' method on the view layer.
Also the action that is mapped to the method can invoke any other methods directly or via reflection.
来源:https://stackoverflow.com/questions/28276191/invoking-methods-in-action