Which statement correctly differentiates @PathVariable and @RequestParam?
4 phương ánCó giải thích
Các phương án trả lời
Chọn một phương ánLời giảiChọn phương án để mở
Đáp án đúng: "@PathVariable binds a URI template variable; @RequestParam binds a query parameter or form field". Với ánh xạ @GetMapping("/users/{id}"), @PathVariable lấy giá trị của biến mẫu id nằm ngay trong đường dẫn, ví dụ /users/42 cho id bằng 42; còn @RequestParam đọc tham số truy vấn sau dấu hỏi như /users?page=2, và với Servlet API thì cũng đọc được trường của form gửi lên dạng application/x-www-form-urlencoded. "@PathVariable binds a query parameter; @RequestParam binds a URI template variable" đảo ngược đúng hai vai trò này. "Both only bind data from HTTP headers" sai vì đọc header là việc của @RequestHeader, còn hai annotation được hỏi đọc dữ liệu từ URI và tham số yêu cầu. "Both require a ModelAndView return type" sai vì kiểu trả về của phương thức xử lý độc lập với cách gắn tham số: có thể trả String tên view, đối tượng được chuyển thành JSON trong @RestController, ResponseEntity hay void.
Cùng phần 5
Which data format is default in REST responses?Có lời giảiCâu hỏiYou have a controller:
@RestController
class TestController {
@GetMapping("/hello")
public String hello() { return "Hi"; }
}
What is the response of GET /hello request?Có lời giảiCâu hỏiWhich component in Spring resolves logical view names to actual templates?Có lời giảiCâu hỏiCả 30 câu của chủ đề30 câu
Xuất hiện trong 1 bộ đề
Đi tiếp từ đây