Spring MVC controller

Similar to the previous example, let's create a simple Controller. Consider the example of a controller here:

    @Controller     public class BasicViewController {       @RequestMapping(value = "/welcome-view")       public String welcome() {         return "welcome";        }     }

A few important things to note are as follows:

  • @RequestMapping(value = "/welcome-view"): We are mapping an URL /welcome-view.
  • public String welcome(): There is no @RequestBody annotation on this method. So, Spring MVC tries to match the string that is returned, welcome, to a view.

Get Mastering Spring 5.0 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.