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;
}
}
同じことを達成するためのより良い方法はありますか?