[포스트맨] form-data로 리스트를 보내고 싶을 때

손경이·2024년 1월 22일
0

2024.01.21
1차 종합 프로젝트
환경 - 스프링부트 3.2.1, 자바 JDK21


💡 포스트맨에서 form-data로 리스트를 보내고 싶을 때

  • 백엔드에서 받는 객체 이름(placeReqDtoList)
    • 예시 : placeReqDtoList[몇 번째 리스트인지 명시].필드
  • 아래 필드는 다 String이다.

  • 서버로 들어오는 형태
placeReqDtoList.getPlaceReqDtoList() = [
PlaceReqDto(
name=아름식당, address=대구 수성, coordinates=20.3, 45
), 
PlaceReqDto(
name=다운식당, address=대구 칠곡, coordinates=46, 12.4
)
]
  • 컨트롤러
@Controller
@RequestMapping("/place")
@RequiredArgsConstructor
public class PlaceController {
    private final PlaceService placeService;
    
	@PostMapping("/save")
	public String savePlaceList(PlaceReqDtoList placeReqDtoList) {
		placeService.save(placeReqDtoList);

		return "domain/place/test";
	}
}
  • h2에 저장되는 형태

참고

https://gist.github.com/qkreltms/f84b817340f1beedf98184f95ffd39ff

0개의 댓글