Step 2 : lombok Step 3 : Screenshot Step 4 : So how to use it
During the development of the project , There will be a lot of pojo. pojo Also called javabean,bean,entity wait , It's all him .
pojo There will be a lot of setter and getter , toString, hashcode, equals wait Everyone pojo Write , Added attribute to write , Reduce the number of attributes to write , still ... Very troublesome .
public class Hero { private int id; private String name; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } @Override public String toString() { return "Hero [id=" + id + ", name=" + name + "]"; } public Hero(int id, String name) { super(); this.id = id; this.name = name; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + id; result = prime * result + ((name == null) ? 0 : name.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Hero other = (Hero) obj; if (id != other.id) return false; if (name == null) { if (other.name != null) return false; } else if (!name.equals(other.name)) return false; return true; } }
To be lazy , We can use lombok. After you use it, you will see the following code , Just add notes
import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.ToString; @Data public class Hero { private int id; private String name; }
import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.ToString; @Data public class Hero { private int id; private String name; }
To prove that I didn't write setter ,getter Can also access , Made a screenshot , You can see IDE The existing methods will pop up automatically , Promise , setter, getter, toString Something , It's all there -_-
In order to use , You need to install plug-ins to ... Next, we will explain how to eclipse and idea Use in .
The official account of programming , Follow and get the latest tutorials and promotions in real time , thank you .
![]()
Q & A area
2021-01-12
Actual development cannot use Lombok
1 One answer
iweb_learn Under review Answer time :2021-11-08
javabean You don't need to subdivide DTO VO Really The construction method can also be manually overridden And if you want to use mybatisplus Must use lombok You can't deny Or combine with the company's development specifications
The answer has been submitted successfully , Auditing . Please
My answer Check the answer record at , thank you
2020-11-04
eclipse Can automatically complete get and set How
The answer has been submitted successfully , Auditing . Please
My answer Check the answer record at , thank you
2020-10-02
The needle doesn't poke , Ease
Please... Before asking questions land
The question has been submitted successfully , Auditing . Please
My question Check the question record at , thank you
|