「Java」@RestControllerでPOST APIを実装する
構文
ResponseEntity<>(文字列, HttpStatus.CREATED);
使用例
@RestController public class ProductServiceController { //オブジェクトpdRepの宣言 private static Map<String, Product> pdRep = new HashMap<>(); //リクエストURI /products @RequestMapping(value = "/products", method = RequestMethod.POST) public ResponseEntity<Object> createProduct(@RequestBody Product product) { pdRep.put(product.getId(), product); //メッセージを返す return new ResponseEntity<>("操作が成功です", HttpStatus.CREATED); } }