Detailed explanation of using annotation to configure action method in struts 2

Using annotations to configure actions can achieve zero configuration, which will transform from pure XML based configuration to annotation based configuration. Using annotations, you can avoid struts. XML in most cases XML file.

The struts 2 framework provides four annotation types related to action, namely parentpackage, namespace, result and action.

Parentpackage: the parentpackage annotation is used to specify the parent package to be inherited from the package where the action is located. The annotation has only one value parameter. Specifies the parent package to inherit.

Example:

Use the parentpackage annotation, whose value is mypackage, indicating that the action needs to inherit the mypackage package,

If there is only one value parameter value in the annotation, or other parameter values use the default value, the value parameter setting can be abbreviated, such as the above code:

Put struts 2-convention-plugin-2 x. Only when the x.jar package is imported into the web application can annotations be used in the action class.

Namespace: the namespace annotation is used to specify the namespace of the package where the action is located. The annotation has only one value parameter, which specifies the namespace to which the action belongs.

When using namespace annotation, you need to start with a slash (/) when naming a namespace.

Use the namespace annotation to specify the namespace of the package where its action is located as / user:

Result: the result annotation is used to define a result map. The annotation contains four parameters,

If the value of the type parameter is nullresult Class, the struts 2 framework will replace the null result with the default result type (servletdispatcherresult) when resolving the result configuration.

Action: the action annotation corresponds to struts The action element in the XML file. This annotation can be used on action classes and methods. This annotation contains the following attributes:

1) Value: optional parameter, indicating the name of the action. 2) results: optional parameter, indicating multiple result mappings of the action. This attribute is used to define a set of result mappings 3) interceptorrefs: optional parameters, representing multiple interceptors of action. This attribute is used to define a group of interceptors (4) params: optional parameters, representing the parameters passed to the action. The format is {key1,...} 5) Exceptionmappings: optional parameter that specifies the exception handling class of action. It is an exception mapping array attribute

summary

The above is all about the detailed explanation of using annotation to configure action method in struts 2. I hope it will be helpful to you. Interested friends can continue to refer to this site: type conversion example code in struts 2, projection of struts 2 through ognl expression, analysis of struts 2 modification upload file size limit method, etc. if you have any questions, you can leave a message at any time. Xiaobian will reply to you in time. Thank you for your support. Here are some good games. You can relax after work and study. The combination of work and rest is the best.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>