「Spring」@PostMapping アノテーションのサンプル

説明
@PostMapping は @RequestMapping(method = RequestMethod.POST) のショートカットとして機能する合成アノテーションです。
サンプルコード

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
@RestController
@RequestMapping("/persons")
class PersonController {
@GetMapping("/{userid}")
public Person getPerson(@PathVariable Long userid) {
// some code
}
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public void add(@RequestBody Person person) {
// some code
}
}
@RestController @RequestMapping("/persons") class PersonController { @GetMapping("/{userid}") public Person getPerson(@PathVariable Long userid) { // some code } @PostMapping @ResponseStatus(HttpStatus.CREATED) public void add(@RequestBody Person person) { // some code } }
@RestController
@RequestMapping("/persons")
class PersonController {

    @GetMapping("/{userid}")
    public Person getPerson(@PathVariable Long userid) {
        // some code
    }

    @PostMapping
    @ResponseStatus(HttpStatus.CREATED)
    public void add(@RequestBody Person person) {
        // some code 
    }
}

 

SpringMVC

Posted by arkgame