Java 개발의 최대 노가다 중 하나는 과연 무었일까요?
그건 바로 View Object ( Model Object,,)의 생성이 아닐까 합니다.
1. 변수 선언하고,,
2. Getter / Setting 설정하고,,
3. 추가로 toString 메소드까지...
뭐,,IDE에서 비교적 많은 부분을 지원해주고 있지만,,
이마져도 귀찮을때가 종종 있죠...
이를 생략하게 해주는 플러그인이 있으니 바로 Lombok
이랬던 코드가..
package com.xxxxxx.app.domain.plan;
import org.springframework.stereotype.Component;
import java.io.Serializable;
import java.util.ArrayList;
/**
* Created by ksyeng on 7/3/15.
* This class is a model for customer
*/
@Component
public class Customer implements Serializable {
private static final long serialVersionUID = -1293803363149548164L;
private String customerNo;
private String name;
private String type;
private String typeName;
private String customerCode;
private String address1;
private String address2;
private String zipcode1;
private String zipcode2;
private String city;
private String country;
private String description;
private String telephone;
private String fax;
private String email;
private String website;
private String registeredDate;
private String updatedDate;
private String valid;
private String cityName;
private String countryName;
private ArrayList<CustomerContact> customerContacts;
public String getTypeName() {
return typeName;
}
public void setTypeName(String typeName) {
this.typeName = typeName;
}
public String getCityName() {
return cityName;
}
public void setCityName(String cityName) {
this.cityName = cityName;
}
public String getCountryName() {
return countryName;
}
public void setCountryName(String countryName) {
this.countryName = countryName;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCustomerNo() {
return customerNo;
}
public void setCustomerNo(String customerNo) {
this.customerNo = customerNo;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getCustomerCode() {
return customerCode;
}
public void setCustomerCode(String customerCode) {
this.customerCode = customerCode;
}
public String getAddress1() {
return address1;
}
public void setAddress1(String address1) {
this.address1 = address1;
}
public String getAddress2() {
return address2;
}
public void setAddress2(String address2) {
this.address2 = address2;
}
public String getZipcode1() {
return zipcode1;
}
public void setZipcode1(String zipcode1) {
this.zipcode1 = zipcode1;
}
public String getZipcode2() {
return zipcode2;
}
public void setZipcode2(String zipcode2) {
this.zipcode2 = zipcode2;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getTelephone() {
return telephone;
}
public void setTelephone(String telephone) {
this.telephone = telephone;
}
public String getFax() {
return fax;
}
public void setFax(String fax) {
this.fax = fax;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getWebsite() {
return website;
}
public void setWebsite(String website) {
this.website = website;
}
public String getRegisteredDate() {
return registeredDate;
}
public void setRegisteredDate(String registeredDate) {
this.registeredDate = registeredDate;
}
public String getUpdatedDate() {
return updatedDate;
}
public void setUpdatedDate(String updatedDate) {
this.updatedDate = updatedDate;
}
public ArrayList<CustomerContact> getCustomerContacts() {
return customerContacts;
}
public void setCustomerContacts(ArrayList<CustomerContact> customerContacts) {
this.customerContacts = customerContacts;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getValid() {
return valid;
}
public void setValid(String valid) {
this.valid = valid;
}
@Override
public String toString() {
return "Customer{" +
"customerNo='" + customerNo + '\'' +
", name='" + name + '\'' +
", type='" + type + '\'' +
", typeName='" + typeName + '\'' +
", customerCode='" + customerCode + '\'' +
", address1='" + address1 + '\'' +
", address2='" + address2 + '\'' +
", zipcode1='" + zipcode1 + '\'' +
", zipcode2='" + zipcode2 + '\'' +
", city='" + city + '\'' +
", country='" + country + '\'' +
", description='" + description + '\'' +
", telephone='" + telephone + '\'' +
", fax='" + fax + '\'' +
", email='" + email + '\'' +
", website='" + website + '\'' +
", registeredDate='" + registeredDate + '\'' +
", updatedDate='" + updatedDate + '\'' +
", valid='" + valid + '\'' +
", cityName='" + cityName + '\'' +
", countryName='" + countryName + '\'' +
", customerContacts=" + customerContacts +
'}';
}
}
이렇게 줄었다.
package com.xxxxx.app.domain.plan;
import lombok.Data;
import org.springframework.stereotype.Component;
import java.io.Serializable;
import java.util.ArrayList;
/**
* Created by ksyeng on 7/3/15.
* This class is a model for customer
*/
@Component
@Data
public class Customer implements Serializable {
private static final long serialVersionUID = -1293803363149548164L;
private String customerNo;
private String name;
private String type;
private String typeName;
private String customerCode;
private String address1;
private String address2;
private String zipcode1;
private String zipcode2;
private String city;
private String country;
private String description;
private String telephone;
private String fax;
private String email;
private String website;
private String registeredDate;
private String updatedDate;
private String valid;
private String cityName;
private String countryName;
private ArrayList<CustomerContact> customerContacts;
}
Lombok을 적용하는 가장 간단한 방법은
library dependency manager에 lombok을 추가해주면된다.
<!-- Lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.4</version>
<scope>provided</scope>
</dependency>
'Programming > Java' 카테고리의 다른 글
Spring context is loaded twice. (0) | 2016.04.28 |
---|---|
mybatis sql 구문 재활용 (0) | 2015.05.19 |
STS (Spring Tool Suites) with Gradle (0) | 2015.01.22 |
Spring 4.0 + myBatis + javaconfig. (2) | 2014.10.24 |
Spring 4.0 + Java Config - web.xml 없애기... (0) | 2014.10.24 |