11.Lombok的使用

 

Lombok的使用

1.引入lombok的依赖

1
2
3
4
5
6
7
   <dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

2.安装lombok的插件

下载lombok.jar

https://projectlombok.org/download

运行java -jar lombok.jar

选择IDE的安装目录(插件jar也会自动扫描电脑中的IDE),然后点击Install/Update

3.lombok的使用

1
2
3
4
5
6
@Data: get(), set(), toString(), NoArgsConstructor()
@Getter: get()
@Setter: set()
@NoArgsConstructor: NoArgsConstructor()
@AllArgsConstructor: AllArgsConstructor()
@ToString: toString()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.springframework.stereotype.Component;

import lombok.Data;

@Component
@Data
public class Person {

private Integer id;
private String userName;
private Integer age;
private String[] hobby;
private List<String> course;
private Set<String> book;
private Map<String, String> score;
private Date birthday;

}