Mapping web request to the Spring Controller; elegantly 🍻

@Requestmapping is your buddy


Annotation to map web request to Spring controller and handler methods.

Basic Criteria

Can be applied at the class or method level in a controller

@RestController@RequestMapping(“/countries”)public class IndexController {@RequestMapping(“/”)String get(){//mapped to hostname:port/country/return “Hello from get”;}@RequestMapping(“/index”)String index(){//mapped to hostname:port/country/index/return “Hello from index”;}}

By Path

method = RequestMethod.GET

HTTP Method

method = POST

HTTP Headers

Headers Attribute

Path Variables