Is there a way to make the struts2 开发者_如何转开发convention plugin use results from a super class?
I'm trying to create a general CRUD, and use general results if there is no implementation in the child class. Is this possible?
Yes, you can.
For an example :
General CRUD
@Results({
@Result(name = "input", location = "input.jsp"),
@Result(location = "input.jsp")
})
public abstract class CrudActionSupport extends ActionSupport {
@Action("update/{entityId}") // wildcard mapping
public String actionUpdate() {
return SUCCESS;
}
}
Action
public class PersonAction extends CrudActionSupport {
}
The annotation at CrudActionSupport will always in effect, except it is overridden in subclass.
e.g.
@Results({
@Result(name = "input", location = "person.jsp"),
@Result(location = "person.jsp")
})
public class PersonAction extends CrudActionSupport {
@Override
public String actionUpdate() {
return SUCCESS;
}
// or
/*
@Action("update/{id}")
@Override
public String actionUpdate() {
return SUCCESS;
}
*/
}
It isn't a facility of Struts2. Such facility could be built, but there are other ways to produce the effect you are looking for.
I recommend using a wild card mapping at this time. It can do what you need and it will work nicely with the conventions plugin (struts.xml rules take precedence over conventions). Annotations or xml which is specific to an action take precedence over the wild card mapping. In other words it works the way you would expect, just try it out.
Something like this is really the reason for me posting: Is it possible to use wildcard method invocation in Struts2 with conventions plugin using only annotations? Although I was thinking of perhaps package level annotations that do the job of wild cards. Anyways the end result would be similar to what you want to do with super classes.
精彩评论