Java / Micronaut Interview questions
What are Micronaut controllers?
A Micronaut controller is a bean annotated with @Controller that maps incoming HTTP requests to methods, similar in role to a Spring MVC @RestController.
The class-level @Controller("/orders") sets a base path, and method-level annotations such as @Get, @Post, @Put, and @Delete map specific routes and HTTP verbs to methods. Path variables, query parameters, and request bodies are bound directly to method parameters using annotations like @PathVariable and @Body.
@Controller("/orders") public class OrderController { @Get("/{id}") public Order get(String id) { ... } @Post public HttpResponse<Order> create(@Body Order order) { ... } }
Controllers are compiled into route metadata at build time, so the router doesn't need reflection to dispatch requests.
More Related questions...