首页 > 其他分享 >@Data 注解

@Data 注解

时间:2022-08-14 23:56:22浏览次数:40  
标签:return name age Object other 注解 Data public

简介

对于 Data 注解基本理解而言就是生成 getter & setter 函数

但是经过探究
不单单有getter & setter 还有 toString方法 hashCode 方法 和 equals 方法。

原代码

import lombok.Data;

@Data
public class TestDTO {
    private Integer age;
    private String name;
}

编译后的代码


public class TestDTO {
    private Integer age;
    private String name;

    public TestDTO() {
    }

    public Integer getAge() {
        return this.age;
    }

    public String getName() {
        return this.name;
    }

    public void setAge(final Integer age) {
        this.age = age;
    }

    public void setName(final String name) {
        this.name = name;
    }

    public boolean equals(final Object o) {
        if (o == this) {
            return true;
        } else if (!(o instanceof TestDTO)) {
            return false;
        } else {
            TestDTO other = (TestDTO)o;
            if (!other.canEqual(this)) {
                return false;
            } else {
                Object this$age = this.getAge();
                Object other$age = other.getAge();
                if (this$age == null) {
                    if (other$age != null) {
                        return false;
                    }
                } else if (!this$age.equals(other$age)) {
                    return false;
                }

                Object this$name = this.getName();
                Object other$name = other.getName();
                if (this$name == null) {
                    if (other$name != null) {
                        return false;
                    }
                } else if (!this$name.equals(other$name)) {
                    return false;
                }

                return true;
            }
        }
    }

    protected boolean canEqual(final Object other) {
        return other instanceof TestDTO;
    }

    public int hashCode() {
        int PRIME = true;
        int result = 1;
        Object $age = this.getAge();
        int result = result * 59 + ($age == null ? 43 : $age.hashCode());
        Object $name = this.getName();
        result = result * 59 + ($name == null ? 43 : $name.hashCode());
        return result;
    }

    public String toString() {
        return "TestDTO(age=" + this.getAge() + ", name=" + this.getName() + ")";
    }
}

标签:return,name,age,Object,other,注解,Data,public
From: https://www.cnblogs.com/eat-too-much/p/16586735.html

相关文章

  • Spring IoC 常用注解手写实现
    执行流程1.  初始化Spring容器时传入配置类,通过配置类的@ComponentScan注解告知Spring需要扫描的包路径,不在扫描包路径下的@Component等注解修饰的Bean不会被IoC容器......
  • SpringBoot-----SpringBoot @Conditional注解自动配置报告
    一、@Conditional简介@Conditional是Spring4新提供的注解,它的作用是按照一定的条件进行判断,满足条件给容器注册Bean。SpringBoot是根据配置文件的内容决定是否创建Bean,以......
  • python 解析from-data数据
    最近在自己尝试使用python基于wsgiref写小型后端框架时需要从前端上传文件到后台,那么要在前端表单中需要添加enctype="multipart/form-data"这样后台拿到的数据不能使用......
  • HCIA-Datacom 2.1 实验一:IPv4编址及IPv4路由基础实验
    实验目的掌握接口IPv4地址的配置方法理解LoopBack接口的作用与含义理解直连路由的产生原则掌握静态路由的配置方法并理解其生效的条件掌握通过PING工具测试网络层联通......
  • 深入理解Spring注解机制(二):元注解解析与属性映射
    前言众所周知,spring从2.5版本以后开始支持使用注解代替繁琐的xml配置,到了springboot更是全面拥抱了注解式配置。平时在使用的时候,点开一些常见的等注解,会发现往往......
  • 一文带你彻底弄懂ES中的doc_values和fielddata
    基本概念这两个概念比较像,所以大部分时候会放在一起说。这两个概念源于Elasticsearch(后面简称ES)除了强大的搜索功能外,还可以支持排序,聚合之类的操作。搜索需要用到倒排索......
  • HCIA-Datacom 1.1实验 华为VRP系统基本操作
    前言:最近有很多老哥,会私信问我一些华为的网络配置和规划,在调试的时候我发现其实我命令也忘了很多,所以写一个文档,方便大家查阅实验介绍:  实现功能:1.完成设备重命名,路......
  • Enterprise Library 5 系列之——Data Access Application
    DataAccessApplication实现任务TaskMethodsFillingaDataSetandupdatingthedatabasefromaDataSet.ExecuteDataSet.Creates,populates,andret......
  • 筛选dataType为4的内容
    #筛选类型数据classShaiXuanLeiXing:def__init__(self,file_name):self.file_name=file_nameself.mubiao_list=[]self.sheqi_lis......
  • 自定义注解进行token校验(转载)
    (18条消息)SpringBoot自定义注解实现Token校验_李秀才的博客-CSDN博客_springboot校验token......