package com.example.model;
import lombok.*;
import java.util.Date;
/**
* Copyright © 2018年08月05日 北京自如信息科技有限公司. All rights reserved.
*
* @Prject: demo_20180801
* @Package: com.example.model
* @Description: 设计模式之-lombok中builder
* @author: Crazy4J
* @date: 2018年08月05日 10:46
* @version: V1.0
*/
@Data
@AllArgsConstructor
//@Builder
public class Student {
private Integer id;
private String name;
private String address;
private Date birthday;
public static Builder builder() {
return new Builder();
}
public static class Builder {
private Integer id;
private String name;
private String address;
private Date birthday;
public Builder id(Integer id) {
this.id = id;
return this;
}
public Builder name(String name) {
this.name = name;
return this;
}
public Builder address(String address) {
this.address = address;
return this;
}
public Builder birthday(Date birthday) {
this.birthday = birthday;
return this;
}
public Student build() {
return new Student(this.id, this.name, this.address, this.birthday);
}
}
public static void main(String[] args) {
Student student = Student.builder().id(1000).name("Crazy_4j")
.address("北京").birthday(new Date()).build();
System.out.println(student);
}
}
设计模式之-lombok中builder
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 站在坟头看电影 文/王牧滋 坐在或站在坟头上观看露天电影,这样的稀奇事你听说过吗?你经历过吗?在我很小的时侯,就跟...