Spring REST Controllers
REST APIs with @RestController, @GetMapping, @PostMapping, @PutMapping, @DeleteMapping, ResponseEntity
1What is the main difference between @RestController and @Controller?
What is the main difference between @RestController and @Controller?
Risposta
@RestController is a composite annotation combining @Controller and @ResponseBody. This means all methods in a @RestController automatically return serialized data (JSON/XML) instead of resolving a view. @RestController is ideal for creating REST APIs, while @Controller is used for traditional web applications with HTML views.
2What is the role of @RequestBody annotation in a REST method?
What is the role of @RequestBody annotation in a REST method?
Risposta
@RequestBody tells Spring to deserialize the HTTP request body (typically JSON or XML) into a Java object. Spring uses an HttpMessageConverter (like Jackson for JSON) to perform this conversion automatically. This is essential for receiving complex data in POST or PUT requests.
3Which annotation should be used to map an HTTP DELETE request?
Which annotation should be used to map an HTTP DELETE request?
Risposta
@DeleteMapping is a specialized annotation introduced in Spring 4.3 to map HTTP DELETE requests concisely. It's a shortcut for @RequestMapping(method = RequestMethod.DELETE). Spring provides similar annotations for each HTTP method: @GetMapping, @PostMapping, @PutMapping, @PatchMapping.
How to extract a path variable from URL in Spring REST?
What is the advantage of using ResponseEntity<T> instead of directly returning an object?
+17 domande da colloquio
Altri argomenti di colloquio Spring Boot
Spring Core - IoC & DI
Spring Boot Auto-Configuration
Spring Boot Starters
Application Properties & YAML
Logging with SLF4J & Logback
Spring Boot DevTools
Spring MVC Basics
Request & Response Handling
Exception Handling
Bean Validation
Spring Data JPA Basics
JPA Entities & Relationships
JPA Queries
Spring Data Repositories
Spring Security Basics
Spring Boot Actuator
Unit Testing with JUnit & Mockito
Spring Boot Testing
Profiles & Environment
RestTemplate & WebClient
Async & Scheduling
Caching with Spring
Spring WebFlux (Reactive)
Spring Transactions
Advanced Authentication & Authorization
JWT & Stateless Security
OAuth2 & Authorization Server
Spring Boot & Docker
Microservices with Spring
Spring Cloud Config
Performance Optimization
GraalVM Native Images
Padroneggia Spring Boot per il tuo prossimo colloquio
Accedi a tutte le domande, flashcards, test tecnici, esercizi di code review e simulatori di colloquio.
Inizia gratis