lombok使用

一、eclipse中安装

    1、直接下载lombok.jar包或者在pom.xml中导入依赖。

		<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
		<dependency>
		    <groupId>org.projectlombok</groupId>
		    <artifactId>lombok</artifactId>
		    <version>1.18.2</version>
		    <scope>provided</scope>
		</dependency>

    2、运行Lombok.jar: Java -jar D:\software\lombok.jar D:\software\lombok.jar这是windows下lombok.jar所在的位置

    3、确认完eclipse的安装路径后,点击install/update按钮,即可安装完成

    4、安装完成之后,请确认eclipse安装路径下是否多了一个lombok.jar包,并且其

配置文件eclipse.ini中是否 添加了如下内容: 
    -javaagent:lombok.jar 
    -Xbootclasspath/a:lombok.jar 
如果上面的答案均为true,那么恭喜你已经安装成功,否则将缺少的部分添加到相应的位置即可 

    5、重启eclipse或myeclipse

    如果安装失败,则直接将maven中的jar包复制到eclipse安装目录中

     1、路径如下:

这里写图片描述

    2、在eclipse.in文件最后加入下面两行:

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

    3、-javaagent:xxx.jar 的jar名称 需要与根目录下的jar名一致,
        不一致,可能会出现eclipse无法启动的情况。重启eclipse,进行代码测试。

二、使用

    1、编译代码后在标注了注解的类上会自动生成想要的方法。

        a、原始文件:

  

package zengxibo.test;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Data
@NoArgsConstructor
@AllArgsConstructor
@ToString(exclude="height")
public class Person {
	private String name;
	private Integer age;
	private Integer height;
}

        b、使用反编译工具反编译\target\test-classes\zengxibo\test文件中的Person.class如下:

package zengxibo.test;

public class Person
{
  private String name;
  private Integer age;
  private Integer height;
  
  public String getName()
  {
    return this.name;
  }
  
  public Integer getAge()
  {
    return this.age;
  }
  
  public Integer getHeight()
  {
    return this.height;
  }
  
  public void setName(String name)
  {
    this.name = name;
  }
  
  public void setAge(Integer age)
  {
    this.age = age;
  }
  
  public void setHeight(Integer height)
  {
    this.height = height;
  }
  
  public boolean equals(Object o)
  {
    if (o == this) {
      return true;
    }
    if (!(o instanceof Person)) {
      return false;
    }
    Person other = (Person)o;
    if (!other.canEqual(this)) {
      return false;
    }
    Object this$name = getName();Object other$name = other.getName();
    if (this$name == null ? other$name != null : !this$name.equals(other$name)) {
      return false;
    }
    Object this$age = getAge();Object other$age = other.getAge();
    if (this$age == null ? other$age != null : !this$age.equals(other$age)) {
      return false;
    }
    Object this$height = getHeight();Object other$height = other.getHeight();return this$height == null ? other$height == null : this$height.equals(other$height);
  }
  
  protected boolean canEqual(Object other)
  {
    return other instanceof Person;
  }
  
  public int hashCode()
  {
    int PRIME = 59;int result = 1;Object $name = getName();result = result * 59 + ($name == null ? 43 : $name.hashCode());Object $age = getAge();result = result * 59 + ($age == null ? 43 : $age.hashCode());Object $height = getHeight();result = result * 59 + ($height == null ? 43 : $height.hashCode());return result;
  }
  
  public Person(String name, Integer age, Integer height)
  {
    this.name = name;this.age = age;this.height = height;
  }
  
  public String toString()
  {
    return "Person(name=" + getName() + ", age=" + getAge() + ")";
  }
  
  public Person() {}
}

三、注解具体含义:

    1、参考:

        a、https://blog.csdn.net/v2sking/article/details/73431364

        b、https://projectlombok.org/features/all

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值