@Accessors: Annotations for customizing getters/setters Use with @ Getter/@ Setter etc. There are three options: "chain", "fluent", and "prefix".
Java : 1.8 Lombok : 1.18.16 (SpringBoot : 2.3.7)
Make the setter a method chain with @Accessors (chain = true)
↓
user.setName("Tom").setAge(24);
Can be described continuously like
public User setName(final String name) {
this.name = name;
return this;
}
@Accessors(fluent = true)
Allow getter/setter names to be used in field names
↓
String name = user.name(); // getter
user.name("Tom"); // setter
Getter/setter can be described by field name like
public String name() {
return this.name;
}
public void name(final String name) {
this.name = name;
return this;
}
@Accessors(prefix = "f")
private String fName;
Define getter/setter using the name excluding the prefix part in ↓
String name = user.getName(); // getter
user.setName("Tom"); // setter
Getter/setter can be described with the name excluding the prefix part like.
public String getName() {
return this.fName;
}
public void setName(final String fName) {
this.fName = fName;
}
@Getter
@Setter
@Accessors(prefix = {"f", "t"})
public class User {
private Integer id;
private String fName;
private Integer tAge;
}
↓ ○ Code that is actually generated
public String getName() {
return this.fName;
}
public void setName(final String fName) {
this.fName = fName;
}
public Integer getAge() {
return this.tAge;
}
public void setAge(final String tAge) {
this.tAge = tAge;
}
Since private Integer id;
does not have "f" or "t" described as prefix, no code is generated.
Recommended Posts