[TIL] 230727 Lombok: is_ _ _ _ Prefix

CountryGirlยท2023๋…„ 7์›” 27์ผ
0

TIL

๋ชฉ๋ก ๋ณด๊ธฐ
35/80

๐Ÿ“Œ ๋ฌธ์ œ์  & ์‹œ๋„ & ํ•ด๊ฒฐ

ํ”„๋ก ํŠธ์—”๋“œ์—์„œ ์ข‹์•„์š” count์™€ ๊ฐ™์ด ์ข‹์•„์š” ํ–ˆ๋Š”์ง€ ์•ˆํ–ˆ๋Š”์ง€๋ฅผ ์•Œ ์ˆ˜ ์žˆ๋Š” ๊ฐ’์„ ๋ณด๋‚ด๋‹ฌ๋ผ๊ณ  ํ–ˆ๋‹ค.

๊ทธ๋ž˜์„œ "isNewsHeart๋ผ๋Š” ์ด๋ฆ„์œผ๋กœ ๋ณด๋‚ผ๊ฒŒ์š”~~~" ๋ผ๊ณ  ํ–ˆ๋‹ค.

NewsHeartResponseDto ์— isNewsHeart๋ฅผ ์ถ”๊ฐ€ํ•ด์ฃผ๊ณ 
Service์— ์ข‹์•„์š”๋ฅผ ๋ˆ„๋ฅด๋ฉด true, ๋‹ค์‹œ ์ทจ์†Œํ•˜๋ฉด false๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” ๋กœ์ง์„ ์ถ”๊ฐ€ํ•ด์ฃผ์—ˆ๋‹ค.

@Getter
public class NewsHeartResponseDto {

    private int newsHeart;
    private boolean isNewsHeart ;

    public NewsHeartResponseDto(int heartCount, boolean isNewsHeart) {
        this.newsHeart = heartCount;
        this.isNewsHeart = isNewsHeart;
    }
}

Postman์—์„œ ํ™•์ธํ•œ ๊ฒฐ๊ณผ.....
isNewsHeart๋Š” ๋‚˜์˜ค์ง€ ์•Š๊ณ  newsHeart๋งŒ ๋‚˜์™”๋‹ค...

์ด๊ฒŒ ๋ญ๋žŒ?

๋ถ„๋ช… ์ง€๊ธˆ๊นŒ์ง€ ํ–ˆ์„ ๋•Œ, Dto์— ์ถ”๊ฐ€ํ•ด์ฃผ๋ฉด Postman์— ์ž˜ ์ถœ๋ ฅ๋๋Š”๋ฐ ์™œ ์•ˆ๋˜์ง€... ๋ผ๊ณ  ์ƒ๊ฐํ–ˆ๋‹ค.

๊ตฌ๊ธ€๋ง์„ ํ•ด๋ณด์•˜๋Š”๋ฐ is๋กœ ํ•˜๋ฉด ์•ˆ๋œ๋‹ค๊ณ  ํ•˜์˜€๋‹ค..

build > classes > ... > news > dto > NewsHeartResponseDto ๋ฅผ ๋ณด์•˜๋‹ค.
newsHeart๋งŒ get ๋ฉ”์„œ๋“œ๊ฐ€ ์žˆ๊ณ  isNewsHeart๋Š” get ๋ฉ”์„œ๋“œ๊ฐ€ ์—†์—ˆ๋‹ค.

Lombok์ด get ๋ฉ”์„œ๋“œ๋ฅผ ์ƒ์„ฑํ•ด์ฃผ์ง€ ์•Š๋Š”๋‹ค !!!!!!!!!!!

์ฐพ์•„๋ณด๋‹ˆ Prefix๋กœ is๊ฐ€ ๋ถ™์œผ๋ฉด get ๋ฉ”์„œ๋“œ๋ฅผ ์ƒ์„ฑํ•˜์ง€ ์•Š๋Š”๋‹ค๊ณ  ํ•œ๋‹ค...

ํ•ด๊ฒฐ๋ฐฉ๋ฒ•

  1. boolean์ด ์•„๋‹Œ Boolean ์œผ๋กœ ๋งŒ๋“ค๊ธฐ (๊ธฐ๋ณธํ˜• โžก๏ธ ์ฐธ์กฐํ˜•)

  2. getIsNewsHeart๋ผ๋Š” get ๋ฉ”์„œ๋“œ ๋งŒ๋“ค์–ด์ฃผ๊ธฐ

    public int getIsNewsHeart(){
    	return this.isNewsHeart;
    }
  3. is Prefix๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ๋ณ€์ˆ˜๋ช…์œผ๋กœ ๋ฐ”๊พธ๊ธฐ

  4. @JsonProperty() ๋‹ฌ์•„์ฃผ๊ธฐ

    @JsonProperty("newsHeart")
    private final int newsHeart;
    
    @JsonProperty("isNewsHeart")
    private final boolean isNewsHeart;

๋‚˜๋Š” Boolean ์ฐธ์กฐํ˜• ๋ณ€์ˆ˜๋กœ ๋งŒ๋“ค์–ด์„œ ์ฃผ์—ˆ๋‹ค!

profile
๐Ÿ’ป๐ŸŒพ์‹œ๊ณจ์†Œ๋…€์˜ ์—‰๋ง์ง•์ฐฝ ๊ฐœ๋ฐœ ์„ฑ์žฅ์ผ์ง€๐ŸŒพ๐Ÿ’ป (2023.05.23 ~)

1๊ฐœ์˜ ๋Œ“๊ธ€

comment-user-thumbnail
2023๋…„ 7์›” 27์ผ

์ข‹์€ ๊ธ€ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค. ์ž์ฃผ ์˜ฌ๊ฒŒ์š” :)

๋‹ต๊ธ€ ๋‹ฌ๊ธฐ