ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

728x90

 

๐ŸŠ ํ”„๋กœํ•„ ๋“ฑ๋ก

{
    "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)

 

[ํ”„๋กœ์ ํŠธ/mnm] Spring - ์ด๋ฏธ์ง€ ์ €์žฅ, ์กฐํšŒ

๐ŸŠ ์ด๋ฏธ์ง€ ์ €์žฅ ํ”„๋กœํ•„ ์ด๋ฏธ์ง€๋ฅผ ์ €์žฅํ•˜๋Š” ํ•จ์ˆ˜๋กœ ์‚ฌ์šฉ์ž ์•„์ด๋””, ์ด๋ฏธ์ง€ ํŒŒ์ผ์„ ์ธ์ž๋กœ ๋ฐ›์•„ ์ด๋ฅผ ๋กœ์ปฌ์— ์ €์žฅํ•œ๋‹ค. // ImageService.java public String saveProfileImage(Long uid, MultipartFile imageFile) t..

programmer-ririhan.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
๋Œ“๊ธ€
๊ณต์ง€์‚ฌํ•ญ
์ตœ๊ทผ์— ์˜ฌ๋ผ์˜จ ๊ธ€