Sobes.tech
Junior — Middle

How are methods called in the controller in your application?

sobes.tech AI

Answer from AI

In Java applications, especially when using the Spring Framework, method calls in controllers occur through handling HTTP requests. Controllers are annotated with @RestController or @Controller, and methods are annotated with types like @GetMapping, @PostMapping, etc. When a request comes to a specific URL, Spring automatically invokes the corresponding controller method.

Example:

@RestController
public class UserController {
    @GetMapping("/users/{id}")
    public User getUser(@PathVariable Long id) {
        // logic to get user by id
        return userService.findById(id);
    }
}

Here, a GET request to /users/{id} calls the getUser method, which takes a parameter from the URL and returns user data.

How are methods called in the controller in your… - sobes.tech