The target for RequestMapping
annotation could be either a method or class. It can be used instead of GetMapping
and PostMapping
annotations that target only methods.
https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/bind/annotation/GetMapping.html
Specifically, @GetMapping is a composed annotation that acts as a
shortcut for @RequestMapping(method = RequestMethod.GET).
https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/bind/annotation/PostMapping.html
Specifically, @PostMapping is a composed annotation that acts as a
shortcut for @RequestMapping(method = RequestMethod.POST).
Assuming your Controller Name is HelloController
, add the RequestMapping
annotation with appropriate methods at Class
level so that it applies automatically to all the paths.
@Controller
@RequestMapping(method={RequestMethod.GET,RequestMethod.POST}, consumes = { MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE },produces = { MediaType.APPLICATION_XML_VALUE,MediaType.APPLICATION_JSON_VALUE },)
class HelloController{
}
This confgiuration can be overridden by annotating it in individual methods.