...

/

Developing a Web Application using @Controller

Developing a Web Application using @Controller

In this lesson, you will be introduced to writing the request handler using @Controller, @RestController, and Thymeleaf for templating.

In the previous lesson, we learned about a few annotations that are offered in Spring Boot and how to manage configurations. In this lesson, we will learn to build a controller.

@Controller

A controller basically handles the request and responds to the client. In Spring Boot, we have @Controller, a special type of @Component, that indicates the annotated class containing the methods that handle incoming requests and returns the response to the client that is initiating the request.

@Controller
public class PlaylistController {
  ...
}

@RequestMapping

@RequestMapping is for binding request endpoints onto handler methods or classes.

@RequestMapping("/playlist")
@Controller
public class PlaylistController {

    @RequestMapping("/{id}")
    public String getAllPlaylists(@PathVariable long id) {
        ....
    }
    
}

In the above code snippet, we see a request handler method getAllPlaylists(...) mapped to the endpoint /playlist/{id}, where id is the path parameter or ...

Access this course and 1400+ top-rated courses and projects.