The use of Lombok

Source: Internet
Author: User

When the project was developed, it was found that the original project code entity class had no attributes in the getter and setter
The code in the project is this stuff.

public class DingDingDepartMentV0 {

    private static final long serialversionuid = -584794972336877603l;
    Department ID
    private Long ID;
    Parent Department ID
    Private Long parentid;
    Department name
    Private String name;
    When a group has been created, whether a new person joins the department will automatically join the group, True indicates that, false is not
    private Boolean autoadduser;
    Whether to synchronize the creation of an enterprise group that associates this department, true indicates yes, false means not
    private Boolean createdeptgroup;



However, when the object is instantiated, it is also found that the methods are called

Partytype Partytype = new Partytype ();
 Partytype.setid (Dingdingdepartmentvo.getid ());
 Partytype.setname (Dingdingdepartmentvo.getname ());

I do not understand, and then there are predecessors told me-– "Lombok"

So it's just a little bit of data to look at, Lombok is designed to eliminate the need for a lot of redundant code when creating entity classes, to look at specific cases:
No use of Lombok:

public class Student {private Integer ID;

    Private String StudentID;

    Private String Studentname;

    private String password;

    private Integer grade;

    Private String Studenttabcol;

    Private Date Unusedbegintime;
    Public Integer GetId () {return id;
    The public void SetId (Integer id) {this.id = ID;
    Public String Getstudentid () {return studentid;
    } public void Setstudentid (String studentid) {This.studentid = StudentID = = null? Null:studentid.trim ();
    Public String Getstudentname () {return studentname; } public void Setstudentname (String studentname) {this.studentname = Studentname = = null? null:studentnam
    E.trim ();
    Public String GetPassword () {return password;
    } public void SetPassword (String password) {this.password = password = = null? Null:password.trim (); Public Integer Getgrade () {return gradE
    The public void Setgrade (Integer grade) {This.grade = grade;
    Public String Getstudenttabcol () {return studenttabcol; } public void Setstudenttabcol (String studenttabcol) {This.studenttabcol = Studenttabcol = = null? null:st
    Udenttabcol.trim ();
    Public Date Getunusedbegintime () {return unusedbegintime;
    The public void Setunusedbegintime (Date unusedbegintime) {this.unusedbegintime = Unusedbegintime; @Override public String toString () {return "student{" + "id=" + ID + " , studentid= ' "+ studentid + ' \ ' +", studentname= ' "+ studentname + ' \ ' +", password= '
                "+ password + ' +", grade= "+ Grade +", studenttabcol= ' "+ studenttabcol + ' \" +
    ", unusedbegintime=" + Unusedbegintime + '} '; }


}

This is the case using the Lombok:

@Data
@NoArgsConstructor
@AllArgsConstructor public
class Student {
    private Integer ID;

    Private String StudentID;

    Private String studentname;

    private String password;

    private Integer grade;

    Private String Studenttabcol;

    Private Date unusedbegintime;
}

Believe that you do not have to say anything, you can see the difference between two kinds.
@Data This annotation can automatically create the methods of Get, set, ToString, Eaquls, hashcode, etc.
@NoArgsConstructor This is a parameterless constructor
@AllArgsConstructor Full parameter constructor
@Setter Set method
@Getter Get method
Of course there are some specific usage and detailed questions can refer to the official website, here is a small video, speak very good
Tip: Install Lombok plug-ins in IJ
First download Lombok of the dependency package, the official website will be able to download directly
If it's maven, add dependencies in Pom.xml

<dependency>
   <groupId>org.projectlombok</groupId>
   <artifactid>lombok</ artifactid>
   <version>1.14.4</version>
</dependency>

Then try to load the plugin in IJ:
Find Preference

Then select Plugins, enter Lombok, if not, select the button in the middle below to automatically install

The next can be practical, of course, this method is not necessarily better than the traditional, I hope to understand the Lombok users have a little help

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.