简体   繁体   English

从Restlet请求获取HTTP GET参数

[英]Get HTTP GET parameters from Restlet request

I am trying to figure out how to get the parameters from a Restlet request object. 我试图弄清楚如何从Restlet请求对象获取参数。

my request comes in as /customer?userId=1 and I want to grab the parameter to pass to my DAO for the query. 我的请求是/ 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;
      }
  }
}

I figured it out.... 我想到了....

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

Please not that there is a shortcut method for that: 请注意,有一个快捷方法:

String paramValue = getQueryValue("userId");

Hope it helps you. 希望它能帮到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM