consumes는 들어오는 데이터 타입 정의
Post Method에서 주로 사용?
@PostMapping(value = "/{service}", consumes = MediaType.APPLICATION_JSON_VALUE)
produces는 보내는 데이터 타입 정의
Get Method에서 주로 사용?
@GetMapping(value = "/{service}", produces = MediaType.APPLICATION_JSON_VALUE)
[참조사이트]
https://mungto.tistory.com/438
[Spring] consumes와 produces의 차이
Mapping을 할때 우리는 받고싶은 데이터를 강제를 함으로써 오류상황을 줄일 수 있다. 이걸 위해 사용하는 것 중 하나가 Media Types이다. 들어오는 데이터와 나가는 데이터를 정하여 처리를 할 수 있
mungto.tistory.com
consumes와 produces의 차이
consumes는 클라이언트가 서버에게 보내는 데이터 타입을 명시.
produces는 서버가 클라이언트에게 반환하는 데이터 타입을 명시.
@PostMapping(path = "/rest/v1/{save}", consumes = MediaType.APPLICATION_JSON_VALUE)
public void save(@RequestBody User user) {
// ...
}
@GetMapping(path = "/rest/v1/{select}", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public User select(@PathVariable String userId) {
// ...
}'java > Controller' 카테고리의 다른 글
| @PathVariable, @RequestParam , @RequestBody (0) | 2023.12.04 |
|---|---|
| Controller return 타입 (0) | 2023.08.17 |