是否可以使用通配符方法调用Struts2中有约定只使用注解插件? [英] Is it possible to use wildcard method invocation in Struts2 with conventions plugin using only annotations?

查看:128
本文介绍了是否可以使用通配符方法调用Struts2中有约定只使用注解插件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何使用的struts.xml中通配符的方法调用,但有可能与注解做到这一点?如果是的话怎么样?

I know how to use wildcard method invocation within struts.xml, but is it possible to do this with annotations? If so how?

推荐答案

您可能已经是现在解决了,但对于那些寻找一个答案,是的,它是可能的。

You probably have it resolved by now, but for those looking for an answer, yes it is possible.

有关通配符映射,请参阅: HTTP://struts.apache .ORG / 2.3.1.2 /文档/通配符mappings.html

For wildcard mapping, refer to: http://struts.apache.org/2.3.1.2/docs/wildcard-mappings.html

从URL中读取参数,可以用这个注解你的方法:

To read params from the url, annotate your method with this:

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的结果会不知道使用什么成功的网址:...编辑/ 123,因此使用@Result需要指向您的文件。还挺defits公约插件存在的目的。

  • 在我想重定向到一个特定的URL的情况下,使用此批注:

    In the case I want to redirect to a specific url, use this annotation:

    @Action(value = "index",
            results={@Result(name = "success", location = "/devices/edit/${entityId}", type = "redirect")}
        )
    

    您需要的ENTITYID(在我的情况的字符串)一个getter / setter方法​​。

    You would need a getter/setter for the entityId (String in my case).

    您也可以拥有先进的wilcard测绘,空间通配符映射...

    You can also have advanced wilcard mapping, namespace wildcard mapping ...

    不要忘记改变struts.xml中添加以下常量。

    Don't forget to change the struts.xml and add the following constants.

    <!-- 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" />
    

    这篇关于是否可以使用通配符方法调用Struts2中有约定只使用注解插件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆