使用Struts 2 REST插件的自定义函数以及其他参数 [英] Custom function with additional argument using Struts 2 REST plugin

查看:31
本文介绍了使用Struts 2 REST插件的自定义函数以及其他参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Struts2 REST插件控制器的URL中是否还有其他参数?

Is there anyway to have additional arguments in the URL of a Struts2 REST plugin controller?

例如,我有:

public class PersonController() implements ModelDriven<Object> {

    private Integer id;
    ...

    public String comment() { ... };
    // Getter and Setter for id
}

已通过

[domain]/person/{id}/comment

但是,我希望能够拥有一个类似

However, what I would like to be able to is have a URL like

[domain]/person/{id}/comment/{commentId}

推荐答案

拥有这样的URL不是REST风格.相反,您可以使用两个URL来访问不同的资源.

It would be not REST style to have such URLs. Instead, you can use two URLs to access different resources.

 [domain]/person/{id}

 [domain]/comment/{commentId}

另一方面,如果您将约定和休息样式映射混合使用,则可以使用 namedVariable regex 模式匹配器来实现您想要的功能.

On the other hand if you mix convention and rest style mapping you can use namedVariable or regex pattern matcher to achieve what you would like to have.

这篇关于使用Struts 2 REST插件的自定义函数以及其他参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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