1.实体对象:
public class User{
private int id;
private String num;
public void User( ){ }
public void setId(int id){
this.id=id;
}
public void setNum(String num){
this.num=num+"id";
}
}
2.实现举例
public class MyBuilder{
private int id;
private String num;
public User build(){
User d=new User();
d.setId(id);
d.setNum(num);
returnt;
}
public MyBuilder setId(int id){
this.id=id;
return this;
}
public MyBuilder setNum(String num){
this.num=num;
return this;
}
}
public class Test{
public static void main(String[] args){
User d=new MyBuilder().setId(10).setNum("hc").build();
}
}
网友评论