【发布时间】:2014-10-25 16:10:00
【问题描述】:
我正在尝试在 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;
}
}
有没有更好的方法来达到同样的效果?
【问题讨论】:
标签: java web-services rest jersey path-parameter