Spring Model-View-Controller web flow
The next step is to add Spring MVC capabilities. In the previous step, the required starter dependencies for the web are added to the pom.xml
file. Next, we will define Spring MVC artifacts in our application.
Since this is a Spring Boot application, we are not required to declare everything from scratch. It is essential to define the controllers and view layer. First, we will declare a Spring MVC controller, as in the following snippet:
@Controller public class BlogController { private Logger logger = LoggerFactory.getLogger(BlogController.class); @GetMapping("/") public String showLandingPage(Model model) { logger.info("This is show home page method "); return "home"; } }
The @Controller
annotation describes this class as a Spring MVC controller. It basically instructs the Spring Boot application that this component will serve a web-based request. It matches the correct URL pattern to call a specific controller and its method.
In the previous...