인프런 커뮤니티 질문&답변
apply 표준함수 체이닝
작성
·
172
0
apply를 여러번 하지않고 this.result 구성할 때 description과 userRequest에 대해서 구성하면 안되나요?
퀴즈
62%나 틀려요. 한번 도전해보세요!
GET 요청 시 URL 경로(예: /users/{id})에 포함된 값을 변수로 받으려면 어떤 어노테이션을 사용할까요?
@RequestParam
@RequestBody
@PathVariable
@ResponseBody
답변 1
0
return UserResponse().apply {
this.result = Result().apply {
this.resultCode = "OK"
this.resultMessage = "성공"
}
//--
this.description = "!!!"
val users = mutableListOf<UserRequest>()
users.add(userRequest)
users.add(UserRequest().apply {
this.name = "a"
this.age = 10
this.email = "a@a.com"
this.address = "a address"
this.phoneNumber = "01012341234"
})
users.add(UserRequest().apply {
this.name = "b"
this.age = 10
this.email = "b@b.com"
this.address = "b address"
this.phoneNumber = "01012341234"
})
this.userRequest = users
}
이렇게 해도 되지 않느냐는 말씀이신가요? 테스트 해봤는데 정상 작동하네요. 이해를 돕기 위해 JSON계층과 똑같은 계층으로 메세지를 채워나간 것 아닌가 추측해봅니다.




