Lombok ์ด๋?
Getter/Setter ๊ทธ๋ฆฌ๊ณ ์์ฑ์๋ค์ Annotation์ผ๋ก ๊ฐํธํ๊ฒ ์ฌ์ฉํ ์ ์๊ฒ ํด์ฃผ๋ ํ๋ฌ๊ทธ์ธ
์์ฐ์ฑ์ ๋ํ์ฃผ๋ ๋๊ตฌ
gradle
์ dependencise ์ Lombok์ ์ถ๊ฐ์์ผ์ผ ํ๋ค.
dependencies{
compile('org.projectlombok:lombok) // lombok ์ถ๊ฐ
implementation 'org.springframework.boot:spring-boot-starter-web'
textImplementation 'org.springframework.boot:spring-boot-starter-web'
}
public class SearchParam {
private String name;
private String id;
private String password;
private int age;
SearchParam(String name, String id, String password, int age){ // ์์ฑ์
this.name = name;
this.id = id;
this.password = password;
this.age = age;
}
public String getName(){ // getter
return name;
}
public void setName(String name){ // setter
this.name = name;
}
}
์ด์ฒ๋ผ getter/setter์ ์ฌ์ฉํ๋ค๊ฑฐ๋ ์์ฑ์๋ฅผ ์ฝ๋์ ์ถ๊ฐ์์ผ์ฃผ๋ฉด ์ฝ๋์ ๊ฐ๋
์ฑ๋ ๋จ์ด์ง ๋ฟ๋๋ฌ ์ฝ๋์ ๊ธธ์ด๊ฐ
๋นํจ์จ์ ์ผ๋ก ๊ธธ์ด์ง๋ ๊ฒ์
@Data
์ด๋
ธํ
์ด์
์ผ๋ก ํด๊ฒฐ ํ๊ฒ ํด์ค๋ค.
@Data // ๊ธฐ๋ณธ ์์ฑ์, getter/setter, toString ์ถ๊ฐ
@AllArgsConstructor //๋ชจ๋ ๋งค๊ฐ๋ณ์๋ฅผ ๊ฐ์ง๋ ์์ฑ์ ์ถ๊ฐ
public class SearchaParam {
private String name;
private String id;
private String password;
private int age;
//getter, setter generator์ ์ฐ์ง ์์๋ ๋๋ค.
}
'๐ Java & Kotlin & Spring > - spring framework +' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Spring & Springboot-JPA] JPA๋ฅผ ์ด์ฉํ CRUD ๋ฉ์๋ ์์ฑํ๊ธฐ - 1 (Entity ์ค์ ๋ฐ Repository ์ค์ ) (0) | 2020.01.27 |
---|---|
[Spring & Springboot ๊ณตํต] HTTP Method - POST (0) | 2020.01.24 |
[Spring & SpringBoot ๊ณตํต] HTTP Method - GET (0) | 2020.01.19 |
[Spring & Springboot-JPA] 1) Springboot์์ Mysql์ JPA ์ ์ฐ๋ํ๊ธฐ. (1) | 2019.11.23 |
์คํ๋ง๋ถํธ ์ REST API (0) | 2019.11.23 |
๋๊ธ