Я читаю книгу "ОТДЫХ Ява"; Сейчас я работаю с примерами из главы 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
Проблема с доступом
/ Клиенты / Sylvie-Van% 20der% 20Vaart.
Причина:
Could not find resource for relative :
/ клиенты / Сильви-Ван% 20der% 20Vaart of
полный путь:
http://localhost:9095/customers/Sylvie-Van%20der%20Vaart
Я попытался просто добавить к регулярному выражению один пробел: @Path ("{first: [a-zA-Z] +} - {last: [a-zA-Z] +}").