What is the primary function of a Controller in a Spring MVC application?

4 phương ánCó giải thích

Các phương án trả lời

Chọn một phương án
Lời giảiChọn phương án để mở
Đáp án đúng: "To handle HTTP requests and return a model and view.". Trong Spring MVC, DispatcherServlet chuyển yêu cầu tới phương thức handler của controller (lớp @Controller với @GetMapping, @PostMapping); controller đọc tham số, gọi service, đặt dữ liệu vào Model rồi trả về tên view hoặc đối tượng ModelAndView để ViewResolver phân giải thành trang, ví dụ trang Thymeleaf. "To manage database connections." sai vì kết nối do DataSource và connection pool lo, còn truy cập dữ liệu nằm ở repository. "To define user interfaces." sai vì giao diện do view template định nghĩa, controller chỉ chọn view và cấp dữ liệu. "To configure application security." là việc của Spring Security qua SecurityFilterChain, chạy ở tầng filter trước khi yêu cầu tới controller.

Cùng phần 5

Xuất hiện trong 2 bộ đề