【问题标题】:Get HTTP GET parameters from Restlet request从 Restlet 请求中获取 HTTP GET 参数
【发布时间】:2010-05-05 13:32:58
【问题描述】:

我正在尝试弄清楚如何从 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;
      }
  }
}

【问题讨论】:

    标签: java rest restlet


    【解决方案1】:

    我想通了……

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

    【讨论】:

    • 我也很难弄明白。
    • 2014 年了,我仍然觉得很难弄清楚 :) 感谢您的解决方案!
    【解决方案2】:

    请注意没有捷径:

    String paramValue = getQueryValue("userId");
    

    希望对你有所帮助。

    【讨论】:

      猜你喜欢
      • 2014-04-11
      • 2021-06-04
      • 1970-01-01
      • 1970-01-01
      • 2015-11-01
      • 2013-11-01
      • 1970-01-01
      • 2016-09-14
      • 2016-05-04
      相关资源
      最近更新 更多