아래와 같이 Primitive Data Type 말고도
List와 같은 타입들을 포함한 데이터를 AJAX를 이용하여 전송받는 경우
@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
public class UserManagementDto {
private String personUniqueNumber;
private String authority_code;
private List<String> authorityCodeList;
private Integer group_id;
private List<Integer> groupIdList;
private String addModifyReason;
private String use_yn;
}
아래와 같이 JSON.stringify 함수로
JSON Object Data를 String으로 변환하여 전송하면 받을 수 있다
$.ajax({
url: "/user/userManagement/modifyUserInfo",
type: "post",
contentType: "application/json",
data:JSON.stringify(modifiedData),
async:false,
success:function(data, textStatus, jqXHR){
},
error: function(jqXHR, textStatus, errorThrown ){
}
})
AJAX에서 JSON.stringify 함수로 데이터를 변환하여 보내고
Controller에서 Parameter에 @RequestBody 어노테이션을 붙여주면
DTO에 바로 매핑된다.
@ResponseBody
@PostMapping("/userManagement/modifyUserInfo")
public HttpStatus modifyUserInfo(@RequestBody UserManagementDto userManagementDto) {
if (userManagementDto!=null) {
//update User Info
userManagementService.modifyUserInfo(userManagementDto);
}
return HttpStatus.OK;
}
'Spring > Spring Framework' 카테고리의 다른 글
@ModelAttribute와 @RequestBody의 차이점 (0) | 2022.09.29 |
---|---|
[Spring 기본개념] Dependency Lookup과 Dependency Injection (Dependency Injection 편) ⓶ (0) | 2022.02.07 |
[Spring 기본개념] Dependency Lookup과 Dependency Injection (Dependency Injection 편) ① (0) | 2022.02.06 |
[Spring 기본개념] Dependency Lookup과 Dependency Injection (Dependency Lookup 편) ② (0) | 2022.02.05 |
개발환경 (0) | 2022.01.23 |
댓글