반응형
@RequestMapping(value = "/Test", method = RequestMethod.POST)
@ResponseBody
public boolean getTest(@RequestBody String str1, @RequestBody String str2) {}
위 코드와 같이 @RequestBody를 2개 사용해서
여러 변수를 넘겨주려는 경우
@RequestBody는 여러개 사용할 수 없기 때문에
이런 방법으로 파라미터를 넘겨줄 수는 없고
{
"str1": "test one",
"str2": "two test"
}
이렇게 2개의 변수를 넘겨야 한다고 치면
let requestModel = {
str1 : "test one",
str2 : "two test"
}
일허게 변수를 선언한 뒤
변수 안에 여러 파라미터로 사용할 값을 넣어준 뒤
@RequestMapping(value = "/Test", method = RequestMethod.POST)
@ResponseBody
public boolean getTest(@RequestBody ModelTest model) {}
public class ModelTest {
private String str1;
private String str2;
}
이런 식으로 모델로 사용할 클래스를 만들어서
여러 파라미터를 받아준 뒤
Getter를 이용해서 끌어 사용하면 된다
반응형
'Spring Framework > Spring' 카테고리의 다른 글
자바 StringUtils.hasText를 이용한 공백 NULL 확인방법 (0) | 2022.04.25 |
---|---|
JsonArray Thymeleaf Table에 출력하는 방법 (0) | 2022.02.09 |
스프링부트 @RestController return HTML로 받는 방법 (0) | 2021.11.12 |
스프링부트 롬복(Lombok) 적용방법 정리 (0) | 2021.11.08 |
Import Spring Getting Started Content은 뭘까? (0) | 2021.10.22 |
댓글