【Video & Communication Platform】
http://study.163.com/course/introduction.htm?courseId=1004329008&utm_campaign=commission&utm_source=400000000155061&utm_medium=share
http://study.163.com/course/introduction.htm?courseId=1004638001&utm_campaign=commission&utm_source=400000000155061&utm_medium=share
https://gitee.com/happyangellxq520/spring-boot
à Spring Boot communication platform
http://412887952-qq-com.iteye.com/blog/2321532
Origin of need:
In the previous two chapters, I introduced lombok and how to install Lombok in Eclipse under indow . Since I use a Mac computer at work and the development tool is an idea , this article introduces the installation and use of the idea on a Mac computer .
Imprint
(2) lombok: 1.16.20;
(3) OS: Mac
(4) Development tools: idea ultimate 2017.2
1. Introduction to Lombok
Lombok has been introduced in the previous two articles, so I won't state it too much here.
2. Installation of Lombok under idea
It is very simple to install lombok under the idea , and it can be done in the idea tool. The specific operations are as follows (note the version of the idea , the version is different, and the menu item names are different):
【打开idea软件】--在左上角的菜单【IntelLIJ IDEA】--【Preferences…】--【Plugins】--点击【Browse repositories…】--【在左上角搜索输入lombok】--【选中Lombok Plugin】--【在右边点击Install】,接下来根据提示进行操作就可以了。
三、Lombok在idea下的使用
3.1 新增依赖
在项目的pom.xml文件中新增lombok的依赖:
<dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <scope>provided</ scope> </dependency>
也可以指定版本号: <version>1.16.20</version>
3.2 新增一个Girl实体类
(1)未使用Lombok的代码
public class Girl { private int id;//主键. private String name;//姓名. private int age;//年龄,女孩的年龄怎么能随便告诉你呢! private double weight;//体重. 这个问女孩,女孩会 ̄へ ̄的. 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; } public int getAge() { returnage; } public void setAge(int age) { this.age = age; } public double getWeight() { return weight; } public void setWeight(double weight) { this.weight = weight; } }
在之前的代码中需要手动生成getter and setter代码。
(2)使用Lombok的代码
import lombok.Data; @Data public class Girl { private int id;//主键. private String name;//姓名. private int age;//年龄,女孩的年龄怎么能随便告诉你呢! private double weight;//体重. 这个问女孩,女孩会 ̄へ ̄的. }
这是什么鬼,好干净好简单哦,这就是Lombok带给我们的。这里在也看不到长长的getter and setter方法了。
3.3 Girl调用
那么使用Lombok之后的属性是否能被getter和setter呢?好想看看那个女孩的体重哦(你想看的不是体重吧,老实说是不是Cup Size),看下调用的代码:
Girl girl = new Girl(); girl.setId(1); girl.setName("Angelababy"); girl.setAge(29); girl.setWeight(45);//单位:千克 System.out.println("姓名:"+girl.getName()+",年龄:"+girl.getAge()+",体重:"+girl.getWeight());
可以获取到,这样使用Lombok之后,就会使得代码变得清爽很多。对于Lombok到这里就结束了,但是Lombok的还需要大家自己去挖掘,这艰巨的任务还是留给你们吧,我还是去new girl()。