티스토리 뷰

 

API를 만들 때 부득이하게 Get요청으로 List로 요청을 보내고 싶을 때가 있다. Spring에서는 @RequestParam을 이용해서 List 형태로 데이터를 받는 것이 가능하다.

@RequestParam은 , (comma)로 구분하여 데이터를 요청하게 되면, 자동으로 데이터를 , (comma) 구분하여 List 형태로 데이터를 변환한다.

@GetMapping(path = "/test", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<ResponseObject> getList(@RequestParam List<Integer> srnoList) throws Exception {
		
	logger.info("*** getList Params ***");
	logger.info("* {}, size {} *", srnoList, srnoList.size());
		
	ResponseObject responseObject = ResponseObject.builder(ServiceConstant.HttpStatus.OK, srnoList, ServiceConstant.ResponseMessage.SUCCESS).build();
		
	return new ResponseEntity<ResponseObject>(responseObject, HttpStatus.OK);
}

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함