咱們在開發過程當中,常常會有一些常規性的,重複性的工做。好比:java
咱們能夠使用lombok插件來解決這個問題。使咱們的編碼效率獲得大幅度的提升!框架
在IDEA 的 File->Settings 面板,並選擇 Plugins 選項,而後點擊 「Browse repositories」。在搜索框輸入」lombok」,結果中找到lombok點擊install重啓IDEA便可。函數
<dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency>
package com.xkt.pojo; import lombok.Data; /** * Created by lzx on 2019/10/9. */ @Data public class Student { private int age; private String name; }
調用對象時 |
---|
直接使用日誌 |
---|
package com.xkt.pojo; import lombok.Builder; import lombok.Data; /** * Created by lzx on 2019/10/9. */ @Data @Builder public class Student { private int age; private String name; }
package com.xkt.service; import com.xkt.pojo.Student; /** * Created by lzx on 2019/10/9. */ public class StudentService { public static void main(String[] args) { Student student = Student.builder().name("張三").age(18).build(); System.out.println(student); } }
測試結果 |
---|
package com.xkt.pojo; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; /** * Created by lzx on 2019/10/9. */ @Data @Builder @AllArgsConstructor @NoArgsConstructor public class Student { private int age; private String name; }
package com.xkt.service; import com.xkt.pojo.Student; /** * Created by lzx on 2019/10/9. */ public class StudentService { public static void main(String[] args) { Student student = new Student(); Student student1 = new Student(18, "張三"); } }