DTO构造的几种方式:
1 构造函数
public class TestDTO {
private String name;
private int age;
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
构造对象的方法:
TestDTO testDTO = new TestDTO();
testDTO.setName("test");
testDTO.setAge(18);
2 静态构造方法
public class TestDTO {
private String name;
private int age;
public static TestDTO of(String name,int age){
TestDTO testDTO = new TestDTO();
testDTO.name = name;
testDTO.age = age;
return testDTO;
}
}
构造对象的方法: