14

我试图弄清楚如何从 Restlet 请求对象中获取参数。

我的请求以 /customer?userId=1 的形式出现,我想获取参数以传递给我的 DAO 进行查询。

public class CustomerResource extends ServerResource
{
  @Get("xml")
  public Representation toXml() throws ResourceException, Exception
  {
      try
      {
          //get param from request
         //call DAO with parameter
      }
      catch(Exception e)
      {
          throw e;
      }
  }
}
4

2 回答 2

30

我想到了....

public class CustomerResource extends ServerResource
{
  @Get("xml")
  public Representation toXml() throws ResourceException, Exception
  {
      try
      {
          //get param from request
          getQuery().getValues("userId")
         //call DAO with parameter
      }
      catch(Exception e)
      {
          throw e;
      }
  }
}
于 2010-05-05T16:08:54.497 回答
7

请注意,有一个快捷方法:

String paramValue = getQueryValue("userId");

希望它可以帮助你。

于 2013-04-15T07:55:25.157 回答