Let's start by creating a simple REST controller as follows:
package com.dineshonjava.masteringspringboot.controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class HelloController { @GetMapping("/hello") String sayHello(){ return "Hello World!!!"; } }
Let's see this small REST controller (HelloController) in detail:
- @RestController annotation: It indicates that this is the controller class and its result writes into the response body and doesn't want to render view
- @GetMapping annotation: It indicates a request handler method and it is a shorthand annotation for @RequestMapping(method = RequestMethod.GET) ...