ํฐ์คํ ๋ฆฌ ๋ทฐ
ํ๋ก์ ํธ
[ํ๋ก์ ํธ/mnm] Spring - ํ๋กํ ๊ด๋ฆฌ REST API ๊ตฌํ
ellie.strong 2021. 11. 17. 16:59728x90
๐ ํ๋กํ ๋ฑ๋ก
{
"response": "success",
"message": "ํ๋กํ ๋ฑ๋ก์ ์ฑ๊ณต์ ์ผ๋ก ์๋ฃํ์ต๋๋ค.",
"data": {
"id": 3,
"user": {
"id": 2,
"email": "2@test.com",
"password": "{bcrypt}$2a$10$eXYG4wE1hESNMNXTVU/gnOq4TECoTzDrt2jdjYtocWkUGPjs47zd2",
"type": false,
"useMatching": true,
"createAt": "2021-11-16T15:07:04.160+00:00",
"removeAt": null,
"roles": [
"ROLE_USER"
],
"enabled": true,
"authorities": [
{
"authority": "ROLE_USER"
}
],
"username": "2@test.com",
"credentialsNonExpired": true,
"accountNonExpired": true,
"accountNonLocked": true
},
"image": "images/profile/2.jpg",
"name": "ํํด๋ฆฌ",
"sex": "female",
"age": 25,
"score": 0
}
}
๐ ์ด๋ฏธ ํ๋กํ์ด ๋ฑ๋ก๋์ด์๋๋ฐ ๋ ๋ฑ๋กํ ๊ฒฝ์ฐ ๋ฌธ์ ๊ฐ ๋ฐ์ํ๋ฏ๋ก ์ด์ ๋ํ ์์ธ์ฒ๋ฆฌ๋ฅผ ํด์ฃผ์ด์ผํ๋ค.
// ProfileService.java
if (!profileRepository.findByUser(user).isEmpty())
throw new Exception("์ด๋ฏธ ํ๋กํ์ด ๋ฑ๋ก๋์ด ์์ต๋๋ค.");
๐ ์ด๋ฏธ์ง ์ ์ฅ, ์กฐํ
[ํ๋ก์ ํธ/mnm] Spring - ์ด๋ฏธ์ง ์ ์ฅ, ์กฐํ (tistory.com)
๐ ํ๋กํ ์์
{
"response": "success",
"message": "ํ๋กํ ์์ ์ ์ฑ๊ณต์ ์ผ๋ก ์๋ฃํ์ต๋๋ค.",
"data": {
"id": 5,
"user": {
"id": 3,
"email": "3@test.com",
"password": "{bcrypt}$2a$10$8Zq5Ql43Es3y5tYoJAiVk..ZUw45YIz.xjlhBSS7Xl270IsEmEhYO",
"type": false,
"useMatching": true,
"createAt": "2021-11-16T15:07:09.931+00:00",
"removeAt": null,
"roles": [
"ROLE_USER"
],
"enabled": true,
"authorities": [
{
"authority": "ROLE_USER"
}
],
"username": "3@test.com",
"credentialsNonExpired": true,
"accountNonExpired": true,
"accountNonLocked": true
},
"image": "images/profile/3.jpg",
"name": "ํํด๋ฆฌ",
"sex": "female",
"age": 24,
"score": 100
}
}
๐ธ ํ๋กํ ์ผ๋ถ ์์
WARN 7480 --- [nio-8080-exec-1] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.multipart.support.MissingServletRequestPartException: Required request part 'image' is not present]
๐ ๋ฆฌํ์คํธ ํ๋ผ๋ฏธํฐ์ Null์ด ๊ฐ๋ฅํ๋๋ก ์ต์ ์ ์ค์ ํด์ค์ผํ๋ค.
@PatchMapping("/profile/{uid}")
public Response editProfile(@PathVariable("uid") Long uid,
@RequestParam(value = "image", required = false) MultipartFile imageFile,
@RequestParam(value = "name", required = false) String name,
@RequestParam(value = "sex", required = false) String sex,
@RequestParam(value = "age", required = false) Integer age,
@RequestParam(value = "score", required = false) Integer score)
{
"response": "success",
"message": "ํ๋กํ ์์ ์ ์ฑ๊ณต์ ์ผ๋ก ์๋ฃํ์ต๋๋ค.",
"data": {
"id": 5,
"user": {
"id": 3,
"email": "3@test.com",
"password": "{bcrypt}$2a$10$8Zq5Ql43Es3y5tYoJAiVk..ZUw45YIz.xjlhBSS7Xl270IsEmEhYO",
"type": false,
"useMatching": true,
"createAt": "2021-11-16T15:07:09.931+00:00",
"removeAt": null,
"roles": [
"ROLE_USER"
],
"enabled": true,
"authorities": [
{
"authority": "ROLE_USER"
}
],
"username": "3@test.com",
"credentialsNonExpired": true,
"accountNonExpired": true,
"accountNonLocked": true
},
"image": "images/profile/3.jpg",
"name": "ํํด๋ฆฌ",
"sex": "female",
"age": 24,
"score": 55
}
}
๐ ํ๋กํ ์ญ์
{
"response": "success",
"message": "ํ๋กํ ์ญ์ ๋ฅผ ์ฑ๊ณต์ ์ผ๋ก ์๋ฃํ์ต๋๋ค.",
"data": null
}
Ref.
thdeodls85 :: [spring boot]@requestparam null ํ์ฉ๋ฐฉ๋ฒ (tistory.com)
728x90
'ํ๋ก์ ํธ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ๋ก์ ํธ/mnm] Spring - ๊ฑฐ์ฃผ ์ ๋ณด ๊ด๋ฆฌ REST API ๊ตฌํ (0) | 2021.11.17 |
---|---|
[ํ๋ก์ ํธ/mnm] Spring - ์ด๋ฏธ์ง ์ ์ฅ, ์กฐํ REST API ๊ตฌํ (4) | 2021.11.17 |
[ํ๋ก์ ํธ/mnm] Spring - ํ์๊ฐ์ , ๋ก๊ทธ์ธ ๊ตฌํ (JWT ์ธ์ฆ) (0) | 2021.11.14 |
[ํ๋ก์ ํธ/mnm] Spring - MySQL ์ฐ๋ (0) | 2021.11.06 |
[ํ๋ก์ ํธ/mnm] Django ์๋ฒ์์ ๋งค์นญ ๊ฒฐ๊ณผ ์๋ตํ๊ธฐ (0) | 2021.11.04 |
๋๊ธ
๊ณต์ง์ฌํญ
์ต๊ทผ์ ์ฌ๋ผ์จ ๊ธ