是否可以在Struts2中使用通配符方法调用,并使用仅使用注释的约定插件?
我知道如何在struts.xml中使用通配符方法调用,但是可以通过注释来实现吗?如果是这样的话,如何解决呢?你现在可能已经解决了,但对于那些寻找答案的人来说,是的,这是可能的 有关通配符映射,请参阅: 要从url读取参数,请使用以下内容对方法进行注释:是否可以在Struts2中使用通配符方法调用,并使用仅使用注释的约定插件?,struts2,annotations,Struts2,Annotations,我知道如何在struts.xml中使用通配符方法调用,但是可以通过注释来实现吗?如果是这样的话,如何解决呢?你现在可能已经解决了,但对于那些寻找答案的人来说,是的,这是可能的 有关通配符映射,请参阅: 要从url读取参数,请使用以下内容对方法进行注释: private String id; @Action(value = "edit/{id}", results={@Result(name = "success", location = "/WEB-INF/views/devi
private String id;
@Action(value = "edit/{id}",
results={@Result(name = "success", location = "/WEB-INF/views/devices/edit.ftl")}
)
public String edit() {
// do something
return SUCCESS;
}
public void setId(String id) {
this.id = id;
}
public String getId() {
return id;
}
- id参数需要一个getter/setter
- 您需要指定结果,因为struts2不知道如何成功使用url:…edit/123,因此需要使用@Result指向您的文件。这有点违背了公约的目的
@Action(value = "index",
results={@Result(name = "success", location = "/devices/edit/${entityId}", type = "redirect")}
)
您需要entityId的getter/setter(在我的例子中是字符串)
您还可以使用高级wilcard映射、命名空间通配符映射
不要忘记更改struts.xml并添加以下常量
<!-- Used for advanced wilcard mapping -->
<constant name="struts.enable.SlashesInActionNames" value="true"/>
<constant name="struts.mapper.alwaysSelectFullNamespace" value="false"/>
<constant name="struts.patternMatcher" value="regex" />
你能举一个你想用注解实现的struts.xml映射的例子吗?我已经很久没看这个了。。。如果“*”与任何其他模式都不匹配,那么我就可以在错误页面上指向某人。我将使用约定插件。