当前位置:网站首页>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;
}
}
边栏推荐
- Where is NPDP product manager certification sacred?
- 张平安:加快云上数字创新,共建产业智慧生态
- Simulate thread communication
- QT控件样式系列(一)之QSlider
- The sooner you understand the four rules of life, the more blessed you will be
- 【最佳网页宽度及其实现】「建议收藏」
- 《2》 Label
- Senior programmers must know and master. This article explains in detail the principle of MySQL master-slave synchronization, and recommends collecting
- batch size设置技巧
- 【oracle】简单的日期时间的格式化与排序问题
猜你喜欢

漏电继电器JD1-100

Auto. JS get all app names of mobile phones

《5》 Table

Annotation初体验

SQL injection - secondary injection and multi statement injection

qt 简单布局 盒子模型 加弹簧

Senior programmers must know and master. This article explains in detail the principle of MySQL master-slave synchronization, and recommends collecting

一条 update 语句的生命经历

Harmonyos fourth training

《4》 Form
随机推荐
Mysql database learning (8) -- MySQL content supplement
漏电继电器JD1-100
Safe landing practice of software supply chain under salesforce containerized ISV scenario
Harmonyos fourth training
磁盘监控相关命令
Leetcode (46) - Full Permutation
模拟线程通信
Autowired注解用于List时的现象解析
What changes will PMP certification bring?
Leetcode(46)——全排列
ThinkPHP关联预载入with
DBSync新增对MongoDB、ES的支持
Redis如何实现多可用区?
Most commonly used high number formula
一条 update 语句的生命经历
As we media, what websites are there to download video clips for free?
Leetcode(417)——太平洋大西洋水流问题
Longest non descent subsequence (LIS) (dynamic programming)
利用OPNET进行网络任意源组播(ASM)仿真的设计、配置及注意点
Batch size setting skills