๐Ÿ“š Study/Spring

์Šคํ”„๋ง(Spring)์—์„œ ์ž์ฃผ ์‚ฌ์šฉํ•˜๋Š” Annotation ๊ฐœ๋… ๋ฐ ์˜ˆ์ œ ์ •๋ฆฌ

kkh1902 2022. 8. 6. 15:42
728x90
๋ฐ˜์‘ํ˜•

1. Annotation์ด๋ž€?

Spring์—์„œ๋Š” Annotation์„ ๋งŽ์ด ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. Annotation์˜ ์—ญํ• ์€ ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๊ด€๋ จ ์„ค๋ช…์€ ์Šคํ”„๋ง ๋นˆ(Spring Bean)์ด๋ž€? ๊ฐœ๋… ์ •๋ฆฌ ๋งํฌ๋ฅผ ์ฐธ์กฐํ•ด์ฃผ์„ธ์š”.

JAVA์—์„œ Annotation ์ด๋ผ๋Š” ๊ธฐ๋Šฅ์ด ์žˆ์Šต๋‹ˆ๋‹ค. ์‚ฌ์ „์ƒ์œผ๋กœ๋Š” ์ฃผ์„์˜ ์˜๋ฏธ์ด์ง€๋งŒ Java ์—์„œ๋Š” ์ฃผ์„ ์ด์ƒ์˜ ๊ธฐ๋Šฅ์„ ๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. Annotation์€ ์ž๋ฐ” ์†Œ์Šค ์ฝ”๋“œ์— ์ถ”๊ฐ€ํ•˜์—ฌ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๋ฉ”ํƒ€๋ฐ์ดํ„ฐ์˜ ์ผ์ข…์ž…๋‹ˆ๋‹ค. ์†Œ์Šค์ฝ”๋“œ์— ์ถ”๊ฐ€ํ•˜๋ฉด ๋‹จ์ˆœ ์ฃผ์„์˜ ๊ธฐ๋Šฅ์„ ํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ ํŠน๋ณ„ํ•œ ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Annotation์€ ํด๋ž˜์Šค์™€ ๋ฉ”์„œ๋“œ์— ์ถ”๊ฐ€ํ•˜์—ฌ ๋‹ค์–‘ํ•œ ๊ธฐ๋Šฅ์„ ๋ถ€์—ฌํ•˜๋Š” ์—ญํ• ์„ ํ•ฉ๋‹ˆ๋‹ค. Annotation์„ ํ™œ์šฉํ•˜์—ฌ Spring Framework๋Š” ํ•ด๋‹น ํด๋ž˜์Šค๊ฐ€ ์–ด๋–ค ์—ญํ• ์ธ์ง€ ์ •ํ•˜๊ธฐ๋„ ํ•˜๊ณ , Bean์„ ์ฃผ์ž…ํ•˜๊ธฐ๋„ ํ•˜๋ฉฐ, ์ž๋™์œผ๋กœ getter๋‚˜ setter๋ฅผ ์ƒ์„ฑํ•˜๊ธฐ๋„ ํ•ฉ๋‹ˆ๋‹ค. ํŠน๋ณ„ํ•œ ์˜๋ฏธ๋ฅผ ๋ถ€์—ฌํ•˜๊ฑฐ๋‚˜ ๊ธฐ๋Šฅ์„ ๋ถ€์—ฌํ•˜๋Š” ๋“ฑ ๋‹ค์–‘ํ•œ ์—ญํ• ์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ด๋Ÿฌํ•œ Annotation์„ ํ†ตํ•˜์—ฌ ์ฝ”๋“œ๋Ÿ‰์ด ๊ฐ์†Œํ•˜๊ณ  ์œ ์ง€๋ณด์ˆ˜ํ•˜๊ธฐ ์‰ฌ์šฐ๋ฉฐ, ์ƒ์‚ฐ์„ฑ์ด ์ฆ๊ฐ€๋ฉ๋‹ˆ๋‹ค. **์ด๋ฒˆ ํฌ์ŠคํŒ…์—์„œ๋Š” **Spring์—์„œ ์‚ฌ์šฉํ•˜๋Š” ๋งŽ์€ Annotation์— ๋Œ€ํ•˜์—ฌ ์ •๋ฆฌํ•ด๋ณด๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค.

2. Spring์˜ ๋Œ€ํ‘œ์ ์ธ Annotation๊ณผ ์—ญํ• 

@Component

๊ฐœ๋ฐœ์ž๊ฐ€ ์ƒ์„ฑํ•œ Class๋ฅผ Spring์˜ Bean์œผ๋กœ ๋“ฑ๋กํ•  ๋•Œ ์‚ฌ์šฉํ•˜๋Š” Annotation์ž…๋‹ˆ๋‹ค. Spring์€ ํ•ด๋‹น Annotation์„ ๋ณด๊ณ  Spring์˜ Bean์œผ๋กœ ๋“ฑ๋กํ•ฉ๋‹ˆ๋‹ค.

@Component(value="myman")
public class Man {
    public Man() {
        System.out.println("hi");
    }
}

@ComponentScan

Spring Framework๋Š” @Component, @Service, @Repository, @Controller, @Configuration ์ค‘ 1๊ฐœ๋ผ๋„ ๋“ฑ๋ก๋œ ํด๋ž˜์Šค๋ฅผ ์ฐพ์œผ๋ฉด, Context์— bean์œผ๋กœ ๋“ฑ๋กํ•ฉ๋‹ˆ๋‹ค. @ComponentScan Annotation์ด ์žˆ๋Š” ํด๋ž˜์Šค์˜ ํ•˜์œ„ Bean์„ ๋“ฑ๋ก ๋  ํด๋ž˜์Šค๋“ค์„ ์Šค์บ”ํ•˜์—ฌ Bean์œผ๋กœ ๋“ฑ๋กํ•ด์ค๋‹ˆ๋‹ค.

@Bean

@Bean Annotation์€ ๊ฐœ๋ฐœ์ž๊ฐ€ ์ œ์–ด๊ฐ€ ๋ถˆ๊ฐ€๋Šฅํ•œ ์™ธ๋ถ€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์™€ ๊ฐ™์€ ๊ฒƒ๋“ค์„ Bean์œผ๋กœ ๋งŒ๋“ค ๋•Œ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

@Controller

Spring์—๊ฒŒ ํ•ด๋‹น Class๊ฐ€ Controller์˜ ์—ญํ• ์„ ํ•œ๋‹ค๊ณ  ๋ช…์‹œํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉํ•˜๋Š” Annotation์ž…๋‹ˆ๋‹ค.

@Controller                   // ์ด Class๋Š” Controller ์—ญํ• ์„ ํ•ฉ๋‹ˆ๋‹ค
@RequestMapping("/user")      // ์ด Class๋Š” /user๋กœ ๋“ค์–ด์˜ค๋Š” ์š”์ฒญ์„ ๋ชจ๋‘ ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค.
public class UserController {
    @RequestMapping(method = RequestMethod.GET)
    public String getUser(Model model) {
        //  GET method, /user ์š”์ฒญ์„ ์ฒ˜๋ฆฌ
    }
}

@RequestHeader

Request์˜ header๊ฐ’์„ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ์œผ๋ฉฐ, ํ•ด๋‹น Annotation์„ ์“ด ๋ฉ”์†Œ๋“œ์˜ ํŒŒ๋ผ๋ฏธํ„ฐ์— ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

@Controller                   // ์ด Class๋Š” Controller ์—ญํ• ์„ ํ•ฉ๋‹ˆ๋‹ค
@RequestMapping("/user")      // ์ด Class๋Š” /user๋กœ ๋“ค์–ด์˜ค๋Š” ์š”์ฒญ์„ ๋ชจ๋‘ ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค.
public class UserController {
    @RequestMapping(method = RequestMethod.GET)
    public String getUser(@RequestHeader(value="Accept-Language") String acceptLanguage) {
        //  GET method, /user ์š”์ฒญ์„ ์ฒ˜๋ฆฌ
    }
}

@RequestMapping

@RequestMapping(value=”“)์™€ ๊ฐ™์€ ํ˜•ํƒœ๋กœ ์ž‘์„ฑํ•˜๋ฉฐ, ์š”์ฒญ ๋“ค์–ด์˜จ URI์˜ ์š”์ฒญ๊ณผ Annotation value ๊ฐ’์ด ์ผ์น˜ํ•˜๋ฉด ํ•ด๋‹น ํด๋ž˜์Šค๋‚˜ ๋ฉ”์†Œ๋“œ๊ฐ€ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค. Controller ๊ฐ์ฒด ์•ˆ์˜ ๋ฉ”์„œ๋“œ์™€ ํด๋ž˜์Šค์— ์ ์šฉ ๊ฐ€๋Šฅํ•˜๋ฉฐ, ์•„๋ž˜์™€ ๊ฐ™์ด ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

  • Class ๋‹จ์œ„์— ์‚ฌ์šฉํ•˜๋ฉด ํ•˜์œ„ ๋ฉ”์†Œ๋“œ์— ๋ชจ๋‘ ์ ์šฉ๋ฉ๋‹ˆ๋‹ค.
  • ๋ฉ”์†Œ๋“œ์— ์ ์šฉ๋˜๋ฉด ํ•ด๋‹น ๋ฉ”์†Œ๋“œ์—์„œ ์ง€์ •ํ•œ ๋ฐฉ์‹์œผ๋กœ URI๋ฅผ ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค.
@Controller                   // ์ด Class๋Š” Controller ์—ญํ• ์„ ํ•ฉ๋‹ˆ๋‹ค
@RequestMapping("/user")      // ์ด Class๋Š” /user๋กœ ๋“ค์–ด์˜ค๋Š” ์š”์ฒญ์„ ๋ชจ๋‘ ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค.
public class UserController {
    @RequestMapping(method = RequestMethod.GET)
    public String getUser(Model model) {
        //  GET method, /user ์š”์ฒญ์„ ์ฒ˜๋ฆฌ
    }
    @RequestMapping(method = RequestMethod.POST)
    public String addUser(Model model) {
        //  POST method, /user ์š”์ฒญ์„ ์ฒ˜๋ฆฌ
    }
    @RequestMapping(value = "/info", method = RequestMethod.GET)
    public String addUser(Model model) {
        //  GET method, /user/info ์š”์ฒญ์„ ์ฒ˜๋ฆฌ
    }
}

@RequestParam

URL์— ์ „๋‹ฌ๋˜๋Š” ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ๋ฉ”์†Œ๋“œ์˜ ์ธ์ž์™€ ๋งค์นญ์‹œ์ผœ, ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ๋ฐ›์•„์„œ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋Š” Annotation์œผ๋กœ ์•„๋ž˜์™€ ๊ฐ™์ด ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. Json ํ˜•์‹์˜ Body๋ฅผ MessageConverter๋ฅผ ํ†ตํ•ด Java ๊ฐ์ฒด๋กœ ๋ณ€ํ™˜์‹œํ‚ต๋‹ˆ๋‹ค.

@Controller                   // ์ด Class๋Š” Controller ์—ญํ• ์„ ํ•ฉ๋‹ˆ๋‹ค
@RequestMapping("/user")      // ์ด Class๋Š” /user๋กœ ๋“ค์–ด์˜ค๋Š” ์š”์ฒญ์„ ๋ชจ๋‘ ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค.
public class UserController {
    @RequestMapping(method = RequestMethod.GET)
    public String getUser(@RequestParam String nickname, @RequestParam(name="old") String age {
        // GET method, /user ์š”์ฒญ์„ ์ฒ˜๋ฆฌ
        // https://naver.com?nickname=dog&old=10
        String sub = nickname + "_" + age;
        ...
    }
}

@RequestBody

Body์— ์ „๋‹ฌ๋˜๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ๋ฉ”์†Œ๋“œ์˜ ์ธ์ž์™€ ๋งค์นญ์‹œ์ผœ, ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ›์•„์„œ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋Š” Annotation์œผ๋กœ ์•„๋ž˜์™€ ๊ฐ™์ด ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ํด๋ผ์ด์–ธํŠธ๊ฐ€ ๋ณด๋‚ด๋Š” HTTP ์š”์ฒญ ๋ณธ๋ฌธ(JSON ๋ฐ XML ๋“ฑ)์„ Java ์˜ค๋ธŒ์ ํŠธ๋กœ ๋ณ€ํ™˜ํ•ฉ๋‹ˆ๋‹ค. ์•„๋ž˜์™€ ๊ฐ™์ด ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

ํด๋ผ์ด์–ธํŠธ๊ฐ€ body์— json or xml ๊ณผ ๊ฐ™์€ ํ˜•ํƒœ๋กœ ํ˜•ํƒœ๋กœ ๊ฐ’(์ฃผ๋กœ ๊ฐ์ฒด)๋ฅผ ์ „์†กํ•˜๋ฉด, ํ•ด๋‹น ๋‚ด์šฉ์„ Java Object๋กœ ๋ณ€ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

@Controller                   // ์ด Class๋Š” Controller ์—ญํ• ์„ ํ•ฉ๋‹ˆ๋‹ค
@RequestMapping("/user")      // ์ด Class๋Š” /user๋กœ ๋“ค์–ด์˜ค๋Š” ์š”์ฒญ์„ ๋ชจ๋‘ ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค.
public class UserController {
    @RequestMapping(method = RequestMethod.POST)
    public String addUser(@RequestBody User user) {
        //  POST method, /user ์š”์ฒญ์„ ์ฒ˜๋ฆฌ
        String sub_name = user.name;
        String sub_old = user.old;
    }
}

@ModelAttribute

ํด๋ผ์ด์–ธํŠธ๊ฐ€ ์ „์†กํ•˜๋Š” HTTP parameter, Body ๋‚ด์šฉ์„ Setter ํ•จ์ˆ˜๋ฅผ ํ†ตํ•ด 1:1๋กœ ๊ฐ์ฒด์— ๋ฐ์ดํ„ฐ๋ฅผ ์—ฐ๊ฒฐ(๋ฐ”์ธ๋”ฉ)ํ•ฉ๋‹ˆ๋‹ค. RequestBody์™€ ๋‹ค๋ฅด๊ฒŒ HTTP Body ๋‚ด์šฉ์€ multipart/form-data ํ˜•ํƒœ๋ฅผ ์š”๊ตฌํ•ฉ๋‹ˆ๋‹ค. @RequestBody๊ฐ€ json์„ ๋ฐ›๋Š” ๊ฒƒ๊ณผ ๋‹ฌ๋ฆฌ @ModenAttribute ์˜ ๊ฒฝ์šฐ์—๋Š” json์„ ๋ฐ›์•„ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.

@ResponseBody

@ResponseBody์€ ๋ฉ”์†Œ๋“œ์—์„œ ๋ฆฌํ„ด๋˜๋Š” ๊ฐ’์ด View ๋กœ ์ถœ๋ ฅ๋˜์ง€ ์•Š๊ณ  HTTP Response Body์— ์ง์ ‘ ์“ฐ์—ฌ์ง€๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. return ์‹œ์— json, xml๊ณผ ๊ฐ™์€ ๋ฐ์ดํ„ฐ๋ฅผ return ํ•ฉ๋‹ˆ๋‹ค.

@Controller                   // ์ด Class๋Š” Controller ์—ญํ• ์„ ํ•ฉ๋‹ˆ๋‹ค
@RequestMapping("/user")      // ์ด Class๋Š” /user๋กœ ๋“ค์–ด์˜ค๋Š” ์š”์ฒญ์„ ๋ชจ๋‘ ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค.
public class UserController {
    @RequestMapping(method = RequestMethod.GET)
    @ResponseBody
    public String getUser(@RequestParam String nickname, @RequestParam(name="old") String age {
        // GET method, /user ์š”์ฒญ์„ ์ฒ˜๋ฆฌ
        // https://naver.com?nickname=dog&old=10
        User user = new User();
        user.setName(nickname);
        user.setAge(age);
        return user;
    }
}

@Autowired

Spring Framework์—์„œ Bean ๊ฐ์ฒด๋ฅผ ์ฃผ์ž…๋ฐ›๊ธฐ ์œ„ํ•œ ๋ฐฉ๋ฒ•์€ ํฌ๊ฒŒ ์•„๋ž˜์˜ 3๊ฐ€์ง€๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. Bean์„ ์ฃผ์ž…๋ฐ›๊ธฐ ์œ„ํ•˜์—ฌ @Autowired ๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. Spring Framework๊ฐ€ Class๋ฅผ ๋ณด๊ณ  Type์— ๋งž๊ฒŒ(Type์„ ๋จผ์ € ํ™•์ธ ํ›„, ์—†์œผ๋ฉด Name ํ™•์ธ) Bean์„ ์ฃผ์ž…ํ•ฉ๋‹ˆ๋‹ค.

  • @Autowired
  • ์ƒ์„ฑ์ž (@AllArgsConstructor ์‚ฌ์šฉ)
  • setter

@GetMapping

RequestMapping(Method=RequestMethod.GET)๊ณผ ๋˜‘๊ฐ™์€ ์—ญํ• ์„ ํ•˜๋ฉฐ, ์•„๋ž˜์™€ ๊ฐ™์ด ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

@Controller                   // ์ด Class๋Š” Controller ์—ญํ• ์„ ํ•ฉ๋‹ˆ๋‹ค
@RequestMapping("/user")      // ์ด Class๋Š” /user๋กœ ๋“ค์–ด์˜ค๋Š” ์š”์ฒญ์„ ๋ชจ๋‘ ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค.
public class UserController {
    @GetMapping("/")
    public String getUser(Model model) {
        //  GET method, /user ์š”์ฒญ์„ ์ฒ˜๋ฆฌ
    }
    
    ////////////////////////////////////
    // ์œ„์™€ ์•„๋ž˜ ๋ฉ”์†Œ๋“œ๋Š” ๋™์ผํ•˜๊ฒŒ ๋™์ž‘ํ•ฉ๋‹ˆ๋‹ค. //
    ////////////////////////////////////

    @RequestMapping(method = RequestMethod.GET)
    public String getUser(Model model) {
        //  GET method, /user ์š”์ฒญ์„ ์ฒ˜๋ฆฌ
    }
}

@PostMapping

RequestMapping(Method=RequestMethod.POST)๊ณผ ๋˜‘๊ฐ™์€ ์—ญํ• ์„ ํ•˜๋ฉฐ, ์•„๋ž˜์™€ ๊ฐ™์ด ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

@Controller                   // ์ด Class๋Š” Controller ์—ญํ• ์„ ํ•ฉ๋‹ˆ๋‹ค
@RequestMapping("/user")      // ์ด Class๋Š” /user๋กœ ๋“ค์–ด์˜ค๋Š” ์š”์ฒญ์„ ๋ชจ๋‘ ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค.
public class UserController {
    @RequestMapping(method = RequestMethod.POST)
    public String addUser(Model model) {
        //  POST method, /user ์š”์ฒญ์„ ์ฒ˜๋ฆฌ
    }

    ////////////////////////////////////
    // ์œ„์™€ ์•„๋ž˜ ๋ฉ”์†Œ๋“œ๋Š” ๋™์ผํ•˜๊ฒŒ ๋™์ž‘ํ•ฉ๋‹ˆ๋‹ค. //
    ////////////////////////////////////

    @PostMapping('/')
    public String addUser(Model model) {
        //  POST method, /user ์š”์ฒญ์„ ์ฒ˜๋ฆฌ
    }
}

@SpringBootTest

Spring Boot Test์— ํ•„์š”ํ•œ ์˜์กด์„ฑ์„ ์ œ๊ณตํ•ด์ค๋‹ˆ๋‹ค.

// DemoApplicationTests.java
package com.example.demo;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
class DemoApplicationTests {

	@Test
	void contextLoads() {

	}

}

@Test

JUnit์—์„œ ํ…Œ์ŠคํŠธ ํ•  ๋Œ€์ƒ์„ ํ‘œ์‹œํ•ฉ๋‹ˆ๋‹ค.

3. Lombok์˜ ๋Œ€ํ‘œ์ ์ธ Annotation๊ณผ ์—ญํ• 

Lombok์€ ์ฝ”๋“œ๋ฅผ ํฌ๊ฒŒ ์ค„์—ฌ์ฃผ์–ด ๊ฐ€๋…์„ฑ์„ ํฌ๊ฒŒ ๋†’ํž ์ˆ˜ ์žˆ๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ž…๋‹ˆ๋‹ค. ๋Œ€ํ‘œ์ ์ธ Annotation์€ ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.

@Setter

Class ๋ชจ๋“  ํ•„๋“œ์˜ Setter method๋ฅผ ์ƒ์„ฑํ•ด์ค๋‹ˆ๋‹ค.

@Getter

Class ๋ชจ๋“  ํ•„๋“œ์˜ Getter method๋ฅผ ์ƒ์„ฑํ•ด์ค๋‹ˆ๋‹ค.

@AllArgsConstructor

Class ๋ชจ๋“  ํ•„๋“œ ๊ฐ’์„ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ๋ฐ›๋Š” ์ƒ์„ฑ์ž๋ฅผ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

@NoArgsConstructor

Class ๊ธฐ๋ณธ ์ƒ์„ฑ์ž๋ฅผ ์ž๋™์œผ๋กœ ์ถ”๊ฐ€ํ•ด์ค๋‹ˆ๋‹ค.

@ToString

Class ๋ชจ๋“  ํ•„๋“œ์˜ toString method๋ฅผ ์ƒ์„ฑํ•œ๋‹ค.

ng)์—์„œ ์ž์ฃผ ์‚ฌ์šฉํ•˜๋Š” Annotation ๊ฐœ๋… ๋ฐ ์˜ˆ์ œ ์ •๋ฆฌ

  •  melonicedlatte
  •  Jul 18, 2021


1. Annotation์ด๋ž€?

Spring์—์„œ๋Š” Annotation์„ ๋งŽ์ด ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. Annotation์˜ ์—ญํ• ์€ ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๊ด€๋ จ ์„ค๋ช…์€ ์Šคํ”„๋ง ๋นˆ(Spring Bean)์ด๋ž€? ๊ฐœ๋… ์ •๋ฆฌ ๋งํฌ๋ฅผ ์ฐธ์กฐํ•ด์ฃผ์„ธ์š”.

JAVA์—์„œ Annotation ์ด๋ผ๋Š” ๊ธฐ๋Šฅ์ด ์žˆ์Šต๋‹ˆ๋‹ค. ์‚ฌ์ „์ƒ์œผ๋กœ๋Š” ์ฃผ์„์˜ ์˜๋ฏธ์ด์ง€๋งŒ Java ์—์„œ๋Š” ์ฃผ์„ ์ด์ƒ์˜ ๊ธฐ๋Šฅ์„ ๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. Annotation์€ ์ž๋ฐ” ์†Œ์Šค ์ฝ”๋“œ์— ์ถ”๊ฐ€ํ•˜์—ฌ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๋ฉ”ํƒ€๋ฐ์ดํ„ฐ์˜ ์ผ์ข…์ž…๋‹ˆ๋‹ค. ์†Œ์Šค์ฝ”๋“œ์— ์ถ”๊ฐ€ํ•˜๋ฉด ๋‹จ์ˆœ ์ฃผ์„์˜ ๊ธฐ๋Šฅ์„ ํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ ํŠน๋ณ„ํ•œ ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Annotation์€ ํด๋ž˜์Šค์™€ ๋ฉ”์„œ๋“œ์— ์ถ”๊ฐ€ํ•˜์—ฌ ๋‹ค์–‘ํ•œ ๊ธฐ๋Šฅ์„ ๋ถ€์—ฌํ•˜๋Š” ์—ญํ• ์„ ํ•ฉ๋‹ˆ๋‹ค. Annotation์„ ํ™œ์šฉํ•˜์—ฌ Spring Framework๋Š” ํ•ด๋‹น ํด๋ž˜์Šค๊ฐ€ ์–ด๋–ค ์—ญํ• ์ธ์ง€ ์ •ํ•˜๊ธฐ๋„ ํ•˜๊ณ , Bean์„ ์ฃผ์ž…ํ•˜๊ธฐ๋„ ํ•˜๋ฉฐ, ์ž๋™์œผ๋กœ getter๋‚˜ setter๋ฅผ ์ƒ์„ฑํ•˜๊ธฐ๋„ ํ•ฉ๋‹ˆ๋‹ค. ํŠน๋ณ„ํ•œ ์˜๋ฏธ๋ฅผ ๋ถ€์—ฌํ•˜๊ฑฐ๋‚˜ ๊ธฐ๋Šฅ์„ ๋ถ€์—ฌํ•˜๋Š” ๋“ฑ ๋‹ค์–‘ํ•œ ์—ญํ• ์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ด๋Ÿฌํ•œ Annotation์„ ํ†ตํ•˜์—ฌ ์ฝ”๋“œ๋Ÿ‰์ด ๊ฐ์†Œํ•˜๊ณ  ์œ ์ง€๋ณด์ˆ˜ํ•˜๊ธฐ ์‰ฌ์šฐ๋ฉฐ, ์ƒ์‚ฐ์„ฑ์ด ์ฆ๊ฐ€๋ฉ๋‹ˆ๋‹ค. **์ด๋ฒˆ ํฌ์ŠคํŒ…์—์„œ๋Š” **Spring์—์„œ ์‚ฌ์šฉํ•˜๋Š” ๋งŽ์€ Annotation์— ๋Œ€ํ•˜์—ฌ ์ •๋ฆฌํ•ด๋ณด๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค.

2. Spring์˜ ๋Œ€ํ‘œ์ ์ธ Annotation๊ณผ ์—ญํ• 

@Component

๊ฐœ๋ฐœ์ž๊ฐ€ ์ƒ์„ฑํ•œ Class๋ฅผ Spring์˜ Bean์œผ๋กœ ๋“ฑ๋กํ•  ๋•Œ ์‚ฌ์šฉํ•˜๋Š” Annotation์ž…๋‹ˆ๋‹ค. Spring์€ ํ•ด๋‹น Annotation์„ ๋ณด๊ณ  Spring์˜ Bean์œผ๋กœ ๋“ฑ๋กํ•ฉ๋‹ˆ๋‹ค.

@Component(value="myman")
public class Man {
    public Man() {
        System.out.println("hi");
    }
}

@ComponentScan

Spring Framework๋Š” @Component, @Service, @Repository, @Controller, @Configuration ์ค‘ 1๊ฐœ๋ผ๋„ ๋“ฑ๋ก๋œ ํด๋ž˜์Šค๋ฅผ ์ฐพ์œผ๋ฉด, Context์— bean์œผ๋กœ ๋“ฑ๋กํ•ฉ๋‹ˆ๋‹ค. @ComponentScan Annotation์ด ์žˆ๋Š” ํด๋ž˜์Šค์˜ ํ•˜์œ„ Bean์„ ๋“ฑ๋ก ๋  ํด๋ž˜์Šค๋“ค์„ ์Šค์บ”ํ•˜์—ฌ Bean์œผ๋กœ ๋“ฑ๋กํ•ด์ค๋‹ˆ๋‹ค.

@Bean

@Bean Annotation์€ ๊ฐœ๋ฐœ์ž๊ฐ€ ์ œ์–ด๊ฐ€ ๋ถˆ๊ฐ€๋Šฅํ•œ ์™ธ๋ถ€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์™€ ๊ฐ™์€ ๊ฒƒ๋“ค์„ Bean์œผ๋กœ ๋งŒ๋“ค ๋•Œ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

@Controller

Spring์—๊ฒŒ ํ•ด๋‹น Class๊ฐ€ Controller์˜ ์—ญํ• ์„ ํ•œ๋‹ค๊ณ  ๋ช…์‹œํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉํ•˜๋Š” Annotation์ž…๋‹ˆ๋‹ค.

@Controller                   // ์ด Class๋Š” Controller ์—ญํ• ์„ ํ•ฉ๋‹ˆ๋‹ค
@RequestMapping("/user")      // ์ด Class๋Š” /user๋กœ ๋“ค์–ด์˜ค๋Š” ์š”์ฒญ์„ ๋ชจ๋‘ ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค.
public class UserController {
    @RequestMapping(method = RequestMethod.GET)
    public String getUser(Model model) {
        //  GET method, /user ์š”์ฒญ์„ ์ฒ˜๋ฆฌ
    }
}

@RequestHeader

Request์˜ header๊ฐ’์„ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ์œผ๋ฉฐ, ํ•ด๋‹น Annotation์„ ์“ด ๋ฉ”์†Œ๋“œ์˜ ํŒŒ๋ผ๋ฏธํ„ฐ์— ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

@Controller                   // ์ด Class๋Š” Controller ์—ญํ• ์„ ํ•ฉ๋‹ˆ๋‹ค
@RequestMapping("/user")      // ์ด Class๋Š” /user๋กœ ๋“ค์–ด์˜ค๋Š” ์š”์ฒญ์„ ๋ชจ๋‘ ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค.
public class UserController {
    @RequestMapping(method = RequestMethod.GET)
    public String getUser(@RequestHeader(value="Accept-Language") String acceptLanguage) {
        //  GET method, /user ์š”์ฒญ์„ ์ฒ˜๋ฆฌ
    }
}

@RequestMapping

@RequestMapping(value=”“)์™€ ๊ฐ™์€ ํ˜•ํƒœ๋กœ ์ž‘์„ฑํ•˜๋ฉฐ, ์š”์ฒญ ๋“ค์–ด์˜จ URI์˜ ์š”์ฒญ๊ณผ Annotation value ๊ฐ’์ด ์ผ์น˜ํ•˜๋ฉด ํ•ด๋‹น ํด๋ž˜์Šค๋‚˜ ๋ฉ”์†Œ๋“œ๊ฐ€ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค. Controller ๊ฐ์ฒด ์•ˆ์˜ ๋ฉ”์„œ๋“œ์™€ ํด๋ž˜์Šค์— ์ ์šฉ ๊ฐ€๋Šฅํ•˜๋ฉฐ, ์•„๋ž˜์™€ ๊ฐ™์ด ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

  • Class ๋‹จ์œ„์— ์‚ฌ์šฉํ•˜๋ฉด ํ•˜์œ„ ๋ฉ”์†Œ๋“œ์— ๋ชจ๋‘ ์ ์šฉ๋ฉ๋‹ˆ๋‹ค.
  • ๋ฉ”์†Œ๋“œ์— ์ ์šฉ๋˜๋ฉด ํ•ด๋‹น ๋ฉ”์†Œ๋“œ์—์„œ ์ง€์ •ํ•œ ๋ฐฉ์‹์œผ๋กœ URI๋ฅผ ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค.
@Controller                   // ์ด Class๋Š” Controller ์—ญํ• ์„ ํ•ฉ๋‹ˆ๋‹ค
@RequestMapping("/user")      // ์ด Class๋Š” /user๋กœ ๋“ค์–ด์˜ค๋Š” ์š”์ฒญ์„ ๋ชจ๋‘ ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค.
public class UserController {
    @RequestMapping(method = RequestMethod.GET)
    public String getUser(Model model) {
        //  GET method, /user ์š”์ฒญ์„ ์ฒ˜๋ฆฌ
    }
    @RequestMapping(method = RequestMethod.POST)
    public String addUser(Model model) {
        //  POST method, /user ์š”์ฒญ์„ ์ฒ˜๋ฆฌ
    }
    @RequestMapping(value = "/info", method = RequestMethod.GET)
    public String addUser(Model model) {
        //  GET method, /user/info ์š”์ฒญ์„ ์ฒ˜๋ฆฌ
    }
}

@RequestParam

URL์— ์ „๋‹ฌ๋˜๋Š” ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ๋ฉ”์†Œ๋“œ์˜ ์ธ์ž์™€ ๋งค์นญ์‹œ์ผœ, ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ๋ฐ›์•„์„œ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋Š” Annotation์œผ๋กœ ์•„๋ž˜์™€ ๊ฐ™์ด ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. Json ํ˜•์‹์˜ Body๋ฅผ MessageConverter๋ฅผ ํ†ตํ•ด Java ๊ฐ์ฒด๋กœ ๋ณ€ํ™˜์‹œํ‚ต๋‹ˆ๋‹ค.

@Controller                   // ์ด Class๋Š” Controller ์—ญํ• ์„ ํ•ฉ๋‹ˆ๋‹ค
@RequestMapping("/user")      // ์ด Class๋Š” /user๋กœ ๋“ค์–ด์˜ค๋Š” ์š”์ฒญ์„ ๋ชจ๋‘ ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค.
public class UserController {
    @RequestMapping(method = RequestMethod.GET)
    public String getUser(@RequestParam String nickname, @RequestParam(name="old") String age {
        // GET method, /user ์š”์ฒญ์„ ์ฒ˜๋ฆฌ
        // https://naver.com?nickname=dog&old=10
        String sub = nickname + "_" + age;
        ...
    }
}

@RequestBody

Body์— ์ „๋‹ฌ๋˜๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ๋ฉ”์†Œ๋“œ์˜ ์ธ์ž์™€ ๋งค์นญ์‹œ์ผœ, ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ›์•„์„œ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋Š” Annotation์œผ๋กœ ์•„๋ž˜์™€ ๊ฐ™์ด ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ํด๋ผ์ด์–ธํŠธ๊ฐ€ ๋ณด๋‚ด๋Š” HTTP ์š”์ฒญ ๋ณธ๋ฌธ(JSON ๋ฐ XML ๋“ฑ)์„ Java ์˜ค๋ธŒ์ ํŠธ๋กœ ๋ณ€ํ™˜ํ•ฉ๋‹ˆ๋‹ค. ์•„๋ž˜์™€ ๊ฐ™์ด ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

ํด๋ผ์ด์–ธํŠธ๊ฐ€ body์— json or xml ๊ณผ ๊ฐ™์€ ํ˜•ํƒœ๋กœ ํ˜•ํƒœ๋กœ ๊ฐ’(์ฃผ๋กœ ๊ฐ์ฒด)๋ฅผ ์ „์†กํ•˜๋ฉด, ํ•ด๋‹น ๋‚ด์šฉ์„ Java Object๋กœ ๋ณ€ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

@Controller                   // ์ด Class๋Š” Controller ์—ญํ• ์„ ํ•ฉ๋‹ˆ๋‹ค
@RequestMapping("/user")      // ์ด Class๋Š” /user๋กœ ๋“ค์–ด์˜ค๋Š” ์š”์ฒญ์„ ๋ชจ๋‘ ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค.
public class UserController {
    @RequestMapping(method = RequestMethod.POST)
    public String addUser(@RequestBody User user) {
        //  POST method, /user ์š”์ฒญ์„ ์ฒ˜๋ฆฌ
        String sub_name = user.name;
        String sub_old = user.old;
    }
}

@ModelAttribute

ํด๋ผ์ด์–ธํŠธ๊ฐ€ ์ „์†กํ•˜๋Š” HTTP parameter, Body ๋‚ด์šฉ์„ Setter ํ•จ์ˆ˜๋ฅผ ํ†ตํ•ด 1:1๋กœ ๊ฐ์ฒด์— ๋ฐ์ดํ„ฐ๋ฅผ ์—ฐ๊ฒฐ(๋ฐ”์ธ๋”ฉ)ํ•ฉ๋‹ˆ๋‹ค. RequestBody์™€ ๋‹ค๋ฅด๊ฒŒ HTTP Body ๋‚ด์šฉ์€ multipart/form-data ํ˜•ํƒœ๋ฅผ ์š”๊ตฌํ•ฉ๋‹ˆ๋‹ค. @RequestBody๊ฐ€ json์„ ๋ฐ›๋Š” ๊ฒƒ๊ณผ ๋‹ฌ๋ฆฌ @ModenAttribute ์˜ ๊ฒฝ์šฐ์—๋Š” json์„ ๋ฐ›์•„ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.

@ResponseBody

@ResponseBody์€ ๋ฉ”์†Œ๋“œ์—์„œ ๋ฆฌํ„ด๋˜๋Š” ๊ฐ’์ด View ๋กœ ์ถœ๋ ฅ๋˜์ง€ ์•Š๊ณ  HTTP Response Body์— ์ง์ ‘ ์“ฐ์—ฌ์ง€๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. return ์‹œ์— json, xml๊ณผ ๊ฐ™์€ ๋ฐ์ดํ„ฐ๋ฅผ return ํ•ฉ๋‹ˆ๋‹ค.

@Controller                   // ์ด Class๋Š” Controller ์—ญํ• ์„ ํ•ฉ๋‹ˆ๋‹ค
@RequestMapping("/user")      // ์ด Class๋Š” /user๋กœ ๋“ค์–ด์˜ค๋Š” ์š”์ฒญ์„ ๋ชจ๋‘ ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค.
public class UserController {
    @RequestMapping(method = RequestMethod.GET)
    @ResponseBody
    public String getUser(@RequestParam String nickname, @RequestParam(name="old") String age {
        // GET method, /user ์š”์ฒญ์„ ์ฒ˜๋ฆฌ
        // https://naver.com?nickname=dog&old=10
        User user = new User();
        user.setName(nickname);
        user.setAge(age);
        return user;
    }
}

@Autowired

Spring Framework์—์„œ Bean ๊ฐ์ฒด๋ฅผ ์ฃผ์ž…๋ฐ›๊ธฐ ์œ„ํ•œ ๋ฐฉ๋ฒ•์€ ํฌ๊ฒŒ ์•„๋ž˜์˜ 3๊ฐ€์ง€๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. Bean์„ ์ฃผ์ž…๋ฐ›๊ธฐ ์œ„ํ•˜์—ฌ @Autowired ๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. Spring Framework๊ฐ€ Class๋ฅผ ๋ณด๊ณ  Type์— ๋งž๊ฒŒ(Type์„ ๋จผ์ € ํ™•์ธ ํ›„, ์—†์œผ๋ฉด Name ํ™•์ธ) Bean์„ ์ฃผ์ž…ํ•ฉ๋‹ˆ๋‹ค.

  • @Autowired
  • ์ƒ์„ฑ์ž (@AllArgsConstructor ์‚ฌ์šฉ)
  • setter

@GetMapping

RequestMapping(Method=RequestMethod.GET)๊ณผ ๋˜‘๊ฐ™์€ ์—ญํ• ์„ ํ•˜๋ฉฐ, ์•„๋ž˜์™€ ๊ฐ™์ด ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

@Controller                   // ์ด Class๋Š” Controller ์—ญํ• ์„ ํ•ฉ๋‹ˆ๋‹ค
@RequestMapping("/user")      // ์ด Class๋Š” /user๋กœ ๋“ค์–ด์˜ค๋Š” ์š”์ฒญ์„ ๋ชจ๋‘ ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค.
public class UserController {
    @GetMapping("/")
    public String getUser(Model model) {
        //  GET method, /user ์š”์ฒญ์„ ์ฒ˜๋ฆฌ
    }
    
    ////////////////////////////////////
    // ์œ„์™€ ์•„๋ž˜ ๋ฉ”์†Œ๋“œ๋Š” ๋™์ผํ•˜๊ฒŒ ๋™์ž‘ํ•ฉ๋‹ˆ๋‹ค. //
    ////////////////////////////////////

    @RequestMapping(method = RequestMethod.GET)
    public String getUser(Model model) {
        //  GET method, /user ์š”์ฒญ์„ ์ฒ˜๋ฆฌ
    }
}

@PostMapping

RequestMapping(Method=RequestMethod.POST)๊ณผ ๋˜‘๊ฐ™์€ ์—ญํ• ์„ ํ•˜๋ฉฐ, ์•„๋ž˜์™€ ๊ฐ™์ด ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

@Controller                   // ์ด Class๋Š” Controller ์—ญํ• ์„ ํ•ฉ๋‹ˆ๋‹ค
@RequestMapping("/user")      // ์ด Class๋Š” /user๋กœ ๋“ค์–ด์˜ค๋Š” ์š”์ฒญ์„ ๋ชจ๋‘ ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค.
public class UserController {
    @RequestMapping(method = RequestMethod.POST)
    public String addUser(Model model) {
        //  POST method, /user ์š”์ฒญ์„ ์ฒ˜๋ฆฌ
    }

    ////////////////////////////////////
    // ์œ„์™€ ์•„๋ž˜ ๋ฉ”์†Œ๋“œ๋Š” ๋™์ผํ•˜๊ฒŒ ๋™์ž‘ํ•ฉ๋‹ˆ๋‹ค. //
    ////////////////////////////////////

    @PostMapping('/')
    public String addUser(Model model) {
        //  POST method, /user ์š”์ฒญ์„ ์ฒ˜๋ฆฌ
    }
}

@SpringBootTest

Spring Boot Test์— ํ•„์š”ํ•œ ์˜์กด์„ฑ์„ ์ œ๊ณตํ•ด์ค๋‹ˆ๋‹ค.

// DemoApplicationTests.java
package com.example.demo;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
class DemoApplicationTests {

	@Test
	void contextLoads() {

	}

}

@Test

JUnit์—์„œ ํ…Œ์ŠคํŠธ ํ•  ๋Œ€์ƒ์„ ํ‘œ์‹œํ•ฉ๋‹ˆ๋‹ค.

3. Lombok์˜ ๋Œ€ํ‘œ์ ์ธ Annotation๊ณผ ์—ญํ• 

Lombok์€ ์ฝ”๋“œ๋ฅผ ํฌ๊ฒŒ ์ค„์—ฌ์ฃผ์–ด ๊ฐ€๋…์„ฑ์„ ํฌ๊ฒŒ ๋†’ํž ์ˆ˜ ์žˆ๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ž…๋‹ˆ๋‹ค. ๋Œ€ํ‘œ์ ์ธ Annotation์€ ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.

@Setter

Class ๋ชจ๋“  ํ•„๋“œ์˜ Setter method๋ฅผ ์ƒ์„ฑํ•ด์ค๋‹ˆ๋‹ค.

@Getter

Class ๋ชจ๋“  ํ•„๋“œ์˜ Getter method๋ฅผ ์ƒ์„ฑํ•ด์ค๋‹ˆ๋‹ค.

@AllArgsConstructor

Class ๋ชจ๋“  ํ•„๋“œ ๊ฐ’์„ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ๋ฐ›๋Š” ์ƒ์„ฑ์ž๋ฅผ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

@NoArgsConstructor

Class ๊ธฐ๋ณธ ์ƒ์„ฑ์ž๋ฅผ ์ž๋™์œผ๋กœ ์ถ”๊ฐ€ํ•ด์ค๋‹ˆ๋‹ค.

@ToString

Class ๋ชจ๋“  ํ•„๋“œ์˜ toString method๋ฅผ ์ƒ์„ฑํ•œ๋‹ค.

728x90
๋ฐ˜์‘ํ˜•