使用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;
}
}
最佳答案
自从我上次使用 ReSTLet 以来已经有一段时间了,但如果我没记错的话,这应该可以工作:
int contact_id = Integer.parseInt(getRequest().getAttributes().get("contact_id"));
关于java - 如何检索分层 URI 中的属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7400996/