【问题标题】:Restlet: Use same resource for "/customer" and "/customer/"Restlet:对“/customer”和“/customer/”使用相同的资源
【发布时间】:2013-02-06 11:19:48
【问题描述】:

我想找到一种解决方案,将 2 条路线用于同一资源。

例如,我是一个资源 CustomerResource,我想将同一资源用于“/customer”和“/customer/”,并添加尾部斜杠。

您对此有什么建议吗?

问候,

编辑:我重写 SpringBeanRouter 以发布带有和不带有斜杠路由的资源:

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);
    }

}

【问题讨论】:

    标签: api restlet


    【解决方案1】:

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

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

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

    【讨论】:

    • 好的,谢谢,因为我希望这是自动的,所以我覆盖了 SpringBeanRouter,正如您在第一篇文章中看到的那样
    猜你喜欢
    • 1970-01-01
    • 2022-01-19
    • 2020-10-26
    • 1970-01-01
    • 1970-01-01
    • 2019-02-10
    • 1970-01-01
    • 2019-02-07
    • 1970-01-01
    相关资源
    最近更新 更多