collection 추가는 다음과 같다.
GET, POST, DELETE 등의 Request 추가는 아래 사진을 참고하자.
GET Request를 해보자.
/{id}는 postman에서 :id와 동일
참고 코드 HelloController.java
package org.ec.example.hello;
import org.ec.example.hello.dto.HelloRequest;
import org.ec.example.hello.dto.HelloResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/hello")
public class HelloController {
private final HelloService helloService; // service 메서드 호출
@Autowired
public HelloController(HelloService helloService) {
this.helloService = helloService;
}
@GetMapping("/{id}") // parameter
public ResponseEntity<HelloResponse> getHello(@PathVariable Long id) {
HelloResponse helloResponse = helloService.getHello(id);
return new ResponseEntity<>(helloResponse, HttpStatus.OK);
}
중략
MySQL에는 변화가 없다.
GET 요청을 하면 MySQL에 변화는 없는 것 맞다. 단지 값을 return해 줄 뿐이다.
그래서 POST 요청을 해보도록 했다.
raw, BODY, JSON
POSTMAN 결과
MySQL 결과
id=1에서 content에 content 값이 저장되었음을 확인할 수 있다.
GET을 하면 반응을 하긴 하는데, returned라고 문구만 뜨고 테이블에서의 변화는 없다.
Dependency Injection 복습1) Constructor Injection (0) | 2022.12.19 |
---|---|
jar 파일, war 파일, apk (0) | 2022.12.03 |
[Spring] Repository에 대한 설명 (0) | 2022.11.27 |
REST API란 (0) | 2022.11.27 |
UML이란? (0) | 2022.11.17 |
댓글 영역