@PostMapping: Difference between revisions
Jump to navigation
Jump to search
(→REST) |
|||
Line 22: | Line 22: | ||
<syntaxhighlight lang='java'> | <syntaxhighlight lang='java'> | ||
@PostMapping(consumes = "application/json") | @RestController | ||
@ResponseStatus(HttpStatus.CREATED) | @RequestMapping(path = "/a", produces = "application/json") | ||
public A post(@RequestBody A a) { | public class AController { | ||
@PostMapping(consumes = "application/json") | |||
@ResponseStatus(HttpStatus.CREATED) | |||
public A post(@RequestBody A a) { | |||
content.put(a.getId(), a); | |||
return a; | |||
} | |||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> |
Revision as of 01:28, 13 March 2019
Internal
Overview
Designates a controller handler method to handle POST requests. The annotation may also contain a sub-path relative to the class-level base path, usually configured with @RequestMapping.
The content of the posted HTML form is presented to the method as a domain model data object: when the form is submitted, the fields in the form are bound to properties of the domain model object instance. In the example below, the form is used to build a taco composition:
@PostMapping
public String processFormContent(Taco taco) {
// ...
return "redirect:/orders/current";
}
REST
@RestController
@RequestMapping(path = "/a", produces = "application/json")
public class AController {
@PostMapping(consumes = "application/json")
@ResponseStatus(HttpStatus.CREATED)
public A post(@RequestBody A a) {
content.put(a.getId(), a);
return a;
}
}
HTTP POST Semantics for REST Applications
Data Members
consume
Specifies what kind of content type(s) the handler is capable of handling.