Spring Boot

Spring MVC Basics

Spring MVC, MVC architecture, DispatcherServlet, @Controller, ViewResolver, Model-View-Controller pattern

20 면접 질문·
Mid-Level
1

Which annotation transforms a Java class into a Spring MVC controller?

답변

@Controller marks a class as a Spring MVC controller that handles HTTP requests. It is a specialization of @Component and allows component scanning to automatically detect the controller. @RestController combines @Controller and @ResponseBody for REST APIs, while @RequestMapping defines URL mappings but doesn't declare a controller by itself.

2

What is the main difference between @Controller and @RestController?

답변

@RestController combines @Controller and @ResponseBody, meaning all methods automatically return serialized data (JSON/XML) instead of view names. With @Controller, you must add @ResponseBody to each method to return data. @RestController is designed for REST APIs, while @Controller is used for traditional web applications with view rendering.

3

How to map a controller method to an HTTP POST request on /users URL?

답변

@PostMapping is the specialized annotation for mapping a method to POST requests on a specific URL. It's a shortcut for @RequestMapping(method = RequestMethod.POST). Other specialized annotations include @GetMapping, @PutMapping, @DeleteMapping, and @PatchMapping. This approach is more readable and concise than @RequestMapping with method attribute.

4

How to retrieve a path variable from a URL like /users/{id}?

5

Which annotation to use to automatically deserialize JSON from HTTP request body?

+17 면접 질문

다음 면접을 위해 Spring Boot을 마스터하세요

모든 질문, flashcards, 기술 테스트, 코드 리뷰 연습, 면접 시뮬레이터에 접근하세요.

무료로 시작하기