开发者

How to retrieve attributes in hierarchical URI?

开发者 https://www.devze.com 2023-04-04 17:33 出处:网络
Using Restlet, how can I retrieve the attributes passed in the URL? Example: http://localhost:8888/contacts/123

Using Restlet, how can I retrieve the attributes passed in the URL?

Example: http://localhost:8888/contacts/123

in here, I want to retrieve the 123 value.

I'm using the next set of lines code:

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;
  开发者_开发百科 }  
 }


Was a while since I last used Restlet, but if I recall correctly, this should work:

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

edit: documentation on routing in Restlet 2.1

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号