import lombok.*;
import org.springframework.beans.BeanUtils;
/*
* @author Lee
* @description 主要用于当参数非常多的时候 进行更改不会影响原有构造 比javabean 的方法更安全
* @date 2019/2/18 14:29
* @param
* @return
**/
//可以使用lombok的注解
//@Builder
@ToString
@Getter
@Setter
public class Car {
private int age;
private String name;
private String des;
private String year;
private String mouth;
private String day;
public static class CarBuilder{
private int age;
private String name;
private String des;
private String year;
private String mouth;
private String day;
public CarBuilder setAge(int age) {
this.age = age;
return this;
}
public CarBuilder setName(String name) {
this.name = name;
return this;
}
public CarBuilder setDes(String des) {
this.des = des;
return this;
}
public CarBuilder setYear(String year) {
this.year = year;
return this;
}
public CarBuilder setMouth(String mouth) {
this.mouth = mouth;
return this;
}
public CarBuilder setDay(String day) {
this.day = day;
return this;
}
public Car build(){
Car car = new Car();
car.setDay(day);
car.setAge(age);
car.setDes(des);
car.setMouth(mouth);
car.setName(name);
car.setYear(year);
return car;
}
}
}
public class CarTest {
@Test
public void test01(){
Car car = new Car.CarBuilder().setAge(1).setDay("20").setDes("12312sddasd").build();
System.out.println(car);
}
}