SpringBoot アノテーション@GetMappingと@PostMappingのサンプル

環境
SpringBoot 2.7.5
java 17
Spring Tool Suite 4.13

書式
@GetMapping(パス)
@PostMapping(パス)

HTTP メソッドに対応するアノテーションが用意されています。
HTTPメソッド GET  アノテーション @GetMapping
HTTPメソッド POST  アノテーション @PostMapping

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
//GET http://localhost:8080/userinfo
@GetMapping("userinfo")
public List<UserData> findAll() {
//処理コード
}
//POST http://localhost:8080/userinfo
@PostMapping("userinfo")
public void create() {
//処理コード
}
//GET http://localhost:8080/userinfo @GetMapping("userinfo") public List<UserData> findAll() { //処理コード } //POST http://localhost:8080/userinfo @PostMapping("userinfo") public void create() { //処理コード }
//GET http://localhost:8080/userinfo
@GetMapping("userinfo")
public List<UserData> findAll() {
  //処理コード
}

//POST http://localhost:8080/userinfo
@PostMapping("userinfo")
public void create() {
  //処理コード
}

 

Spring Boot

Posted by arkgame