Let's create a simple Spring MVC controller as follows:
@Controller public class BasicController { @RequestMapping(value = "/welcome") @ResponseBody public String welcome() { return "Welcome to Spring MVC"; } }
A few important things to note here are as follows:
- @Controller: This defines a Spring MVC controller that can contain request mappings--mapping URLs to controller methods.
- @RequestMapping(value = "/welcome"): This defines a mapping of the URL /welcome to the welcome method. When the browser sends a request to /welcome, Spring MVC does the magic and executes the welcome method.
- @ResponseBody: In this specific context, the text returned by the welcome method is sent out to the browser as the ...