当前位置:网站首页>Lombok插件
Lombok插件
2022-07-06 23:34:00 【PIKapikaaaa】
Lombok插件
lombok插件简介
lombok是一个插件,用途是使用注解给你类里面的字段,自动的加上属性构造器,ToString方法,Equals方法等等。
比较方便的一点是,你在更改字段的时候,lombok会立即发生改变以保持和你代码的一致性。
常用的 lombok 注解介绍
@Getter :可以自动生成参数的getter方法。
@Setter :可以自动生成参数的setter方法
@ToString :调用toString()方法,可以输出实体类中所有属性的值
@RequiredArgsConstructor:会生成一个包含常量,和标识了NotNull的变量的构造方法。生成的构造方法是私有的private。这个用的很少。
@EqualsAndHashCode
1.它会生成equals和hashCode方法
2.默认使用非静态的属性
3.可以通过exclude参数排除不需要生成的属性
@EqualsAndHashCode(exclude = {“表中字段1”, “表中字段2”})
4.可以通过of参数来指定需要生成的属性
@EqualsAndHashCode(of = {“表中字段1”, “表中字段2”})
5.它默认不调用父类的方法,只使用本类定义的属性进行操作,可以使用callSuper=true来解决,会在@Data中进行讲解。
@Data:这个注解其实是以上五个注解的合体—@Getter、@Setter、@RequiredArgsConstructor、@ToString、@EqualsAndHashCode
@NoArgsConstructor:生成一个无参数的构造方法。
@AllArgsConstructor:生成一个包含所有变量的构造方法。
@Value:这个注解要和Spring的@Value注解区分,Spring的是从配置文件读取内容,这个注解是在类中的所有字段默认全部声明为private final类型,只会生成Getter方法,不会生成Setter方法,很少用。
@Cleanup:主要用于关闭资源使用。
idea安装lombok插件
首先我们需要安装IntelliJ IDEA中的lombok插件。
打开IntelliJ IDEA后点击菜单栏中的File–>Settings,或者使用快捷键Ctrl+Alt+S进入到设置页面

安装完后重启idea—【本人idea版本为2021】
lombok插件的使用
@Data
@AllArgsConstructor
@NoArgsConstructor
// 用来表示实体类和数据库表的映射关系,当实体类名称和表的名称不相同时一定加 @TableName
@TableName("user")
public class User {
// 表示使用数据库自增策略
@TableId(type = IdType.AUTO)
private Long id;
// 当实体类中的属性名与数据库的字段名不一致的时候,可以使用 注解:@TableField 来表示映射关系
@TableField("name")
private String username;
private Integer age;
private String email;
// @TableField(exist = false) 表示 数据库表中没有该字段的情况,映射转换sql语句的时候不会拼上此字段
@TableField(exist = false)
private Date birthday;
public User(String name, Integer age, String email) {
this.username = name;
this.age = age;
this.email = email;
}
}
me = name;
this.age = age;
this.email = email;
}
}
边栏推荐
- CentOS 7.9 installing Oracle 21C Adventures
- Knapsack problem (01 knapsack, complete knapsack, dynamic programming)
- 漏电继电器JD1-100
- 利用OPNET进行网络仿真时网络层协议(以QoS为例)的使用、配置及注意点
- Disk monitoring related commands
- 【opencv】图像形态学操作-opencv标记不同连通域的位置
- ThinkPHP Association preload with
- How Alibaba cloud's DPCA architecture works | popular science diagram
- 【js组件】date日期显示。
- The sooner you understand the four rules of life, the more blessed you will be
猜你喜欢
![[question] Compilation Principle](/img/ce/71f8409ba2cebd497bed0210290895.png)
[question] Compilation Principle

SQL injection - secondary injection and multi statement injection

【js组件】自定义select
![[JS component] date display.](/img/26/9bfc752c8c9a933a8e33b59e0488a2.jpg)
[JS component] date display.

漏电继电器JD1-100

AOSP ~binder communication principle (I) - Overview

MySQL数据库学习(8) -- mysql 内容补充

Is it necessary to renew the PMP certificate?

Longest palindrome substring (dynamic programming)

高压漏电继电器BLD-20
随机推荐
高压漏电继电器BLD-20
Two person game based on bevy game engine and FPGA
QT控件样式系列(一)之QSlider
人体传感器好不好用?怎么用?Aqara绿米、小米之间到底买哪个
Under the trend of Micah, orebo and apple homekit, how does zhiting stand out?
Aidl and service
【oracle】简单的日期时间的格式化与排序问题
【QT】自定义控件-Loading
利用OPNET进行网络指定源组播(SSM)仿真的设计、配置及注意点
[QT] custom control loading
[opencv] image morphological operation opencv marks the positions of different connected domains
Window scheduled tasks
数字化创新驱动指南
最长回文子串(动态规划)
[JS component] date display.
Batch size setting skills
Complete code of C language neural network and its meaning
QSlider of QT control style series (I)
When deleting a file, the prompt "the length of the source file name is greater than the length supported by the system" cannot be deleted. Solution
《2》 Label