@RestController: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
(3 intermediate revisions by the same user not shown) | |||
Line 5: | Line 5: | ||
=Overview= | =Overview= | ||
A convenience [[Spring_Dependency_Injection_and_Inversion_of_Control_Container_Concepts#Annotation-based_Configuration_with_.40Autowired_and_Stereotype_Annotations|stereotype]] annotations that it is itself annotated with [[@Controller]] and [[@ResponseBody]]. It is used to designate REST controller components. | A convenience [[Spring_Dependency_Injection_and_Inversion_of_Control_Container_Concepts#Annotation-based_Configuration_with_.40Autowired_and_Stereotype_Annotations|stereotype]] annotations that it is itself annotated with [[@Controller]] and [[@ResponseBody]]. It is used to designate REST controller components. Being a stereotype annotation, marks the class for discovery by [[Spring_Dependency_Injection_and_Inversion_of_Control_Container_Concepts#Component_Scanning|component scanning]]. Also, because the annotation is also annotated with [[@ResponseBody]], all handler methods in the controller have their return value written directly into the body of the response: [[@RequestMapping]] methods assume [[@ResponseBody]] semantics by default. Annotating the class with [[@Controller]] and each handler methods with [[@ResponseBody]] would achieve the same result. | ||
=Base Path= | |||
The controller's base path is specified as the "path" member of [[@RequestMapping]] annotation: | |||
<syntaxhighlight lang='java'> | |||
@RestController | |||
@RequestMapping(path = "/a", produces = "application/json") | |||
public class AController { | |||
... | |||
} | |||
</syntaxhighlight> |
Latest revision as of 19:39, 12 March 2019
Internal
Overview
A convenience stereotype annotations that it is itself annotated with @Controller and @ResponseBody. It is used to designate REST controller components. Being a stereotype annotation, marks the class for discovery by component scanning. Also, because the annotation is also annotated with @ResponseBody, all handler methods in the controller have their return value written directly into the body of the response: @RequestMapping methods assume @ResponseBody semantics by default. Annotating the class with @Controller and each handler methods with @ResponseBody would achieve the same result.
Base Path
The controller's base path is specified as the "path" member of @RequestMapping annotation:
@RestController
@RequestMapping(path = "/a", produces = "application/json")
public class AController {
...
}