表达包括空格的Resteasy路径

时间:2010-12-19 12:34:39

标签: regex path expression resteasy

我正在阅读“RESTful Java”一书;现在我正在使用第4章的例子。 我想更改表达式以接受带空格的名称。我已将表达式更改为“[a-zA-Z] +”,但它不起作用。有没有办法使这项工作?

非常感谢

   @GET
   @Path("{first : [a-zA-Z]+}-{last:[a-zA-Z]+}")
   @Produces("application/xml")
   public StreamingOutput getCustomerFirstLast(@PathParam("first") String first,
                                               @PathParam("last") String last)
   {
    System.out.println(String.format("Parameters. First=%s; Last=%s", first, last));
      Customer found = null;
      for (Customer cust : customerDB.values())
      {
         if (cust.getFirstName().equals(first) && cust.getLastName().equals(last))
         {
            found = cust;
            break;
         }
      }
      if (found == null)
      {
         throw new WebApplicationException(Response.Status.NOT_FOUND);
      }
      final Customer customer = found;
      return new StreamingOutput()
      {
         public void write(OutputStream outputStream) throws IOException, WebApplicationException
         {
            outputCustomer(outputStream, customer);
         }
      };
   }

编辑:我不清楚。

当我尝试网址时:/ customers / Sylvie-Van%20der%20Vaart我收到以下错误:

  

HTTP错误404

     

访问问题   /客户/西尔维面包车%20der%20Vaart。   原因是:

Could not find resource for relative :
     

/ customers / Sylvie-Van%20der%20Vaart of   完整路径:   http://localhost:9095/customers/Sylvie-Van%20der%20Vaart

我只是想在正则表达式中添加一个空格:@Path(“{first:[a-zA-Z] +} - {last:[a-zA-Z] +}”)。

1 个答案:

答案 0 :(得分:1)