我正在尝试在 REST URI 中接收作为逗号分隔值的字符串列表(示例:
http://localhost:8080/com.vogella.jersey.first/rest/todo/test/1/abc,test
,其中 abc 和 test 是传入的逗号分隔值)。
目前我将此值作为字符串获取,然后将其拆分以获取各个值。当前代码:
@Path("/todo")
public class TodoResource {
// This method is called if XMLis request
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/test/{id: .*}/{name: .*}")
public Todo getXML(@PathParam("id") String id,
@PathParam("name") String name) {
Todo todo = new Todo();
todo.setSummary("This is my first todo, id received is : " + id
+ "name is : " + Arrays.asList(name.split("\\s*,\\s*")));
todo.setDescription("This is my first todo");
TodoTest todoTest = new TodoTest();
todoTest.setDescription("abc");
todoTest.setSummary("xyz");
todo.setTodoTest(todoTest);
return todo;
}
}
有没有更好的方法来达到同样的效果?