正常写一个类是,每一个私有属性都要生成get,set方法
public class Book
{
private Integer id;
private String type;
private String name;
private String description;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
有了lombok这个类之后:可以大大简化代码:
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class Book
{
private Integer id;
private String type;
private String name;
private String description;
}
甚至可以再简化一些,把两个注解再合并:
import lombok.Data;
@Data
public class Book
{
private Integer id;
private String type;
private String name;
private String description;
}
这个Date注解非常狠,直接包括了get/set方法,toString方法,hashcode方法,equsls方法