首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Restlet:对"/customer“和"/customer/”使用相同的资源

Restlet:对"/customer“和"/customer/”使用相同的资源
EN

Stack Overflow用户
提问于 2013-02-06 19:19:49
回答 1查看 148关注 0票数 0

我想找到一个解决方案,为相同的资源使用两个路由。

例如,我是一名资源客户,我想对"/customer“和”/ CustomerResource /“使用相同的资源,并添加一个尾部斜杠。

你对此有什么建议吗?

致以敬意,

编辑:我覆盖了SpringBeanRouter以发布带有和不带有尾部斜杠路径的资源:

代码语言:javascript
复制
public class MySpringBeanRouter extends SpringBeanRouter {

    @Override
    public TemplateRoute attach(String pathTemplate, Restlet target) {
        if(pathTemplate != null && pathTemplate.endsWith("/"))
            super.attach(pathTemplate.substring(0, pathTemplate.length() - 1), target);

        return super.attach(pathTemplate, target);
    }

}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-02-07 15:25:56

可以在两个不同的路由下附加相同的资源类:

router.attach("/customer",CustomerServerResource.class);

router.attach("/customer/",CustomerServerResource.class);

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14727780

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档