私は「RESTfulJava」という本を読んでいます。現在、第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);
}
};
}
編集:私は明確ではありませんでした。
次のURLを試してみると:/ customers / Sylvie-Van%20der%20Vaart次のエラーが発生します。
HTTPエラー404
/ Customers / Sylvie-Van%20der%20Vaartへのアクセスに問題があります。理由:
Could not find resource for relative :
フルパスの/customers/ Sylvie-Van%20der%20Vaart: http:// localhost:9095 / customers / Sylvie-Van%20der%20Vaart
正規表現に1つのスペースを追加しようとしました:@Path( "{first:[a-zA-Z] +}-{last:[a-zA-Z] +}")。