【问题标题】:How to retrieve attributes in hierarchical URI?如何检索分层 URI 中的属性?
【发布时间】:2011-11-16 02:11:27
【问题描述】:

使用 Restlet,我如何检索 URL 中传递的属性?

示例:http://localhost:8888/contacts/123

在这里,我要检索 123 的值。

我正在使用下一组代码:

router.attach("contacts/{contact_id}", ContactResource.class);

public class ContactResource extends ServerResource
{
   @Get
   public ContactDetail retrieve()
   {
     //how to retrieve the contact_id value?
     return null;
   }  
 }

【问题讨论】:

    标签: java google-app-engine url-rewriting restlet


    【解决方案1】:

    自从我上次使用 Restlet 已经有一段时间了,但如果我没记错的话,这应该可以工作:

    int contact_id = Integer.parseInt(getRequest().getAttributes().get("contact_id"));
    

    编辑:documentation on routing in Restlet 2.1

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-03
      • 1970-01-01
      • 2011-06-07
      • 2023-03-10
      • 1970-01-01
      • 2014-02-25
      • 1970-01-01
      相关资源
      最近更新 更多