IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

Lombok安装和使用

IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

前言

Lombok是一个开源项目,其使用简单的注解的形式来帮助我们简化消除一些必须有但显得很臃肿的 java 代码,特别是对于POJO。

Lombok的官网:https://projectlombok.org/

在官网上还有一个简短的视频讲解,介绍了Lombok的功能及使用方法。

Lombok安装

使用 Lombok 是需要安装的,如果不安装,IDE 则无法解析 Lombok 注解。先在官网下载最新版本的 JAR 包,现在是 1.16.16版本。

安装方式有两种:自动安装和手动安装,推荐自动安装。

1、 双击下载下来的JAR包安装Lombok(推荐)

双击后,Lombok会发现已安装好的IDE,然后按照Lombok的指示进行安装。如果Lombok无法发现IDE,则可以使用第二种方法进行安装。

2、 IDE手动安装Lombok

将 lombok.jar 复制到eclipse.ini 所在的文件夹目录下,然后编辑eclipse.ini,在最后面插入两行:

 -Xbootclasspath/a:lombok.jar
 -javaagent:lombok.jar

然后重启eclipse。

Lombok使用

Lombok 提供的注解不多,可以参考官方视频的讲解和官方文档:https://projectlombok.org/features/index.html

下面介绍几个我常用的 Lombok 注解:

@Data       // 注解在类上;提供类所有属性的 getting 和 setting 方法,此外还提供了equals、canEqual、hashCode、toString 方法
@Setter    // 注解在属性上;为属性提供 setting 方法
@Getter    // 注解在属性上;为属性提供 getting 方法
@Log4j     // 注解在类上;为类提供一个 属性名为log 的 log4j 日志对象
@NoArgsConstructor     // 注解在类上;为类提供一个无参的构造方法
@AllArgsConstructor    // 注解在类上;为类提供一个全参的构造方法

下面是简单示例:

不使用Lombok

 public class User implements Serializable {
     /**
      * 
      */
     private static final long serialVersionUID = -1332337734725440336L;

     private Long id;

     private String username;

     private String password;

     private Date timestamp;

     private String remark;

     public User() {
         super();
     }

     public User(Long id, String username, String password, Date timestamp, String remark) {
         super();
         this.id = id;
         this.username = username;
         this.password = password;
         this.timestamp = timestamp;
         this.remark = remark;
     }

     public Long getId() {
         return id;
     }

     public void setId(Long id) {
         this.id = id;
     }

     public String getUsername() {
         return username;
     }

     public void setUsername(String username) {
         this.username = username;
     }

     public String getPassword() {
         return password;
     }

     public void setPassword(String password) {
         this.password = password;
     }

     public Date getTimestamp() {
         return timestamp;
     }

     public void setTimestamp(Date timestamp) {
         this.timestamp = timestamp;
     }

     public String getRemark() {
         return remark;
     }

     public void setRemark(String remark) {
         this.remark = remark;
     }
 }

使用Lombok

 @Data
 @NoArgsConstructor
 @AllArgsConstructor
 public class User implements Serializable {
     /**
      * 
      */
     private static final long serialVersionUID = -1332337734725440336L;

     private Long id;

     private String username;

     private String password;

     private Date timestamp;

     private String remark;
 }

上面的两个 Java 类,从作用上来看,它们的效果是一样的,相比较之下,很明显,使用 Lombok 要简洁许多,特别是在类的属性较多的情况下,同时也避免了修改字段名字时候忘记修改方法名所犯的低级错误。最后需要注意的是,在使用 Lombok 注解的时候记得要导入 lombok.jar 包到工程。

文章永久链接:https://tech.souyunku.com/?p=15227


Warning: A non-numeric value encountered in /data/wangzhan/tech.souyunku.com.wp/wp-content/themes/dux/functions-theme.php on line 1154
赞(72) 打赏



未经允许不得转载:搜云库技术团队 » Lombok安装和使用

IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码
IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

评论 抢沙发

大前端WP主题 更专业 更方便

联系我们联系我们

觉得文章有用就打赏一下文章作者

微信扫一扫打赏

微信扫一扫打赏


Fatal error: Uncaught Exception: Cache directory not writable. Comet Cache needs this directory please: `/data/wangzhan/tech.souyunku.com.wp/wp-content/cache/comet-cache/cache/https/tech-souyunku-com/index.q`. Set permissions to `755` or higher; `777` might be needed in some cases. in /data/wangzhan/tech.souyunku.com.wp/wp-content/plugins/comet-cache/src/includes/traits/Ac/ObUtils.php:367 Stack trace: #0 [internal function]: WebSharks\CometCache\Classes\AdvancedCache->outputBufferCallbackHandler() #1 /data/wangzhan/tech.souyunku.com.wp/wp-includes/functions.php(5109): ob_end_flush() #2 /data/wangzhan/tech.souyunku.com.wp/wp-includes/class-wp-hook.php(303): wp_ob_end_flush_all() #3 /data/wangzhan/tech.souyunku.com.wp/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters() #4 /data/wangzhan/tech.souyunku.com.wp/wp-includes/plugin.php(470): WP_Hook->do_action() #5 /data/wangzhan/tech.souyunku.com.wp/wp-includes/load.php(1097): do_action() #6 [internal function]: shutdown_action_hook() #7 {main} thrown in /data/wangzhan/tech.souyunku.com.wp/wp-content/plugins/comet-cache/src/includes/traits/Ac/ObUtils.php on line 367