Serving web content with Spring MVC

In Spring MVC, HTTP requests are handled by controllers. Controllers are classes that have been annotated with @Controller—similar to how we annotate rest controllers with @RestController. The best way to understand the way controllers work is to have an example to scrutinize. Let us create a simple Spring MVC controller that handles HTTP GET requests sent to the /say/hello path by returning a view, which has the responsibility of rendering an HTML page to a user.

Create a controller package in com.example.placereviewer and add the following class to it:

package com.example.placereviewer.controllerimport org.springframework.stereotype.Controllerimport org.springframework.web.bind.annotation.GetMapping

Get Kotlin Programming By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.