Ứng dụng deploy với context root /shop. Request GET /shop/api/orders/42 cho ra giá trị id và expand là gì?
@ApplicationPath("/api")
public class RestApp extends Application { }
@Path("/orders")
public class OrderResource {
@GET
@Path("/{id}")
@Produces(MediaType.APPLICATION_JSON)
public Order find(@PathParam("id") long id,
@QueryParam("expand") @DefaultValue("false") boolean expand) {
// ...
}
}
Xem đáp án và giải thích
URL đầy đủ = context root + @ApplicationPath + @Path của class + @Path của method. @PathParam lấy từ template {...}, @QueryParam lấy từ query string và tự convert sang kiểu Java. Bảng đối chiếu với Spring MVC: @Path ~ @RequestMapping, @PathParam ~ @PathVariable, @QueryParam ~ @RequestParam.