• Lombok的@Data注解包含的方法(没有全参构造方法)


    Lombok的@Data注解包含的方法(没有全参构造方法)

    结论:

    @Data : 注解在实体类上,提供类的get、set、equals、hashCode、canEqual、toString、无参构造方法注意:没有全参构造方法。

    测试:

    1.Maven引入依赖

      		<dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <optional>true</optional>
            </dependency>
    
    • 1
    • 2
    • 3
    • 4
    • 5

    2.安装lombok插件

    在这里插入图片描述

    3.编写实体类

    /**
     * 用户数据的实体类
     */
    @Data
    public class User implements Serializable {
        private Integer uid;
        private String username;
        private String password;
        private String salt;
        private String phone;
        private String email;
        private Integer gender;
        private String avatar;
        private Integer isDelete;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    4.编译

    点击compile进行编译。
    在这里插入图片描述

    5.查看target文件

    在这里插入图片描述

    6.编译后的源代码

     public class User implements Serializable {
        private Integer uid;
        private String username;
        private String password;
        private String salt;
        private String phone;
        private String email;
        private Integer gender;
        private String avatar;
        private Integer isDelete;
     
        public User() {
        }
     
        public Integer getUid() {
            return this.uid;
        }
     
        public String getUsername() {
            return this.username;
        }
     
        public String getPassword() {
            return this.password;
        }
     
        public String getSalt() {
            return this.salt;
        }
     
        public String getPhone() {
            return this.phone;
        }
     
        public String getEmail() {
            return this.email;
        }
     
        public Integer getGender() {
            return this.gender;
        }
     
        public String getAvatar() {
            return this.avatar;
        }
     
        public Integer getIsDelete() {
            return this.isDelete;
        }
     
        public void setUid(final Integer uid) {
            this.uid = uid;
        }
     
        public void setUsername(final String username) {
            this.username = username;
        }
     
        public void setPassword(final String password) {
            this.password = password;
        }
     
        public void setSalt(final String salt) {
            this.salt = salt;
        }
     
        public void setPhone(final String phone) {
            this.phone = phone;
        }
     
        public void setEmail(final String email) {
            this.email = email;
        }
     
        public void setGender(final Integer gender) {
            this.gender = gender;
        }
     
        public void setAvatar(final String avatar) {
            this.avatar = avatar;
        }
     
        public void setIsDelete(final Integer isDelete) {
            this.isDelete = isDelete;
        }
     
        public boolean equals(final Object o) {
            if (o == this) {
                return true;
            } else if (!(o instanceof User)) {
                return false;
            } else {
                User other = (User)o;
                if (!other.canEqual(this)) {
                    return false;
                } else {
                    label119: {
                        Object this$uid = this.getUid();
                        Object other$uid = other.getUid();
                        if (this$uid == null) {
                            if (other$uid == null) {
                                break label119;
                            }
                        } else if (this$uid.equals(other$uid)) {
                            break label119;
                        }
     
                        return false;
                    }
     
                    Object this$gender = this.getGender();
                    Object other$gender = other.getGender();
                    if (this$gender == null) {
                        if (other$gender != null) {
                            return false;
                        }
                    } else if (!this$gender.equals(other$gender)) {
                        return false;
                    }
     
                    label105: {
                        Object this$isDelete = this.getIsDelete();
                        Object other$isDelete = other.getIsDelete();
                        if (this$isDelete == null) {
                            if (other$isDelete == null) {
                                break label105;
                            }
                        } else if (this$isDelete.equals(other$isDelete)) {
                            break label105;
                        }
     
                        return false;
                    }
     
                    Object this$username = this.getUsername();
                    Object other$username = other.getUsername();
                    if (this$username == null) {
                        if (other$username != null) {
                            return false;
                        }
                    } else if (!this$username.equals(other$username)) {
                        return false;
                    }
     
                    label91: {
                        Object this$password = this.getPassword();
                        Object other$password = other.getPassword();
                        if (this$password == null) {
                            if (other$password == null) {
                                break label91;
                            }
                        } else if (this$password.equals(other$password)) {
                            break label91;
                        }
     
                        return false;
                    }
     
                    Object this$salt = this.getSalt();
                    Object other$salt = other.getSalt();
                    if (this$salt == null) {
                        if (other$salt != null) {
                            return false;
                        }
                    } else if (!this$salt.equals(other$salt)) {
                        return false;
                    }
     
                    label77: {
                        Object this$phone = this.getPhone();
                        Object other$phone = other.getPhone();
                        if (this$phone == null) {
                            if (other$phone == null) {
                                break label77;
                            }
                        } else if (this$phone.equals(other$phone)) {
                            break label77;
                        }
     
                        return false;
                    }
     
                    label70: {
                        Object this$email = this.getEmail();
                        Object other$email = other.getEmail();
                        if (this$email == null) {
                            if (other$email == null) {
                                break label70;
                            }
                        } else if (this$email.equals(other$email)) {
                            break label70;
                        }
     
                        return false;
                    }
     
                    Object this$avatar = this.getAvatar();
                    Object other$avatar = other.getAvatar();
                    if (this$avatar == null) {
                        if (other$avatar != null) {
                            return false;
                        }
                    } else if (!this$avatar.equals(other$avatar)) {
                        return false;
                    }
     
                    return true;
                }
            }
        }
     
        protected boolean canEqual(final Object other) {
            return other instanceof User;
        }
     
        public int hashCode() {
            int PRIME = true;
            int result = 1;
            Object $uid = this.getUid();
            int result = result * 59 + ($uid == null ? 43 : $uid.hashCode());
            Object $gender = this.getGender();
            result = result * 59 + ($gender == null ? 43 : $gender.hashCode());
            Object $isDelete = this.getIsDelete();
            result = result * 59 + ($isDelete == null ? 43 : $isDelete.hashCode());
            Object $username = this.getUsername();
            result = result * 59 + ($username == null ? 43 : $username.hashCode());
            Object $password = this.getPassword();
            result = result * 59 + ($password == null ? 43 : $password.hashCode());
            Object $salt = this.getSalt();
            result = result * 59 + ($salt == null ? 43 : $salt.hashCode());
            Object $phone = this.getPhone();
            result = result * 59 + ($phone == null ? 43 : $phone.hashCode());
            Object $email = this.getEmail();
            result = result * 59 + ($email == null ? 43 : $email.hashCode());
            Object $avatar = this.getAvatar();
            result = result * 59 + ($avatar == null ? 43 : $avatar.hashCode());
            return result;
        }
     
        public String toString() {
            Integer var10000 = this.getUid();
            return "User(uid=" + var10000 + ", username=" + this.getUsername() + ", password=" + this.getPassword() + ", salt=" + this.getSalt() + ", phone=" + this.getPhone() + ", email=" + this.getEmail() + ", gender=" + this.getGender() + ", avatar=" + this.getAvatar() + ", isDelete=" + this.getIsDelete() + ")";
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
    • 223
    • 224
    • 225
    • 226
    • 227
    • 228
    • 229
    • 230
    • 231
    • 232
    • 233
    • 234
    • 235
    • 236
    • 237
    • 238
    • 239
    • 240
    • 241
    • 242
    • 243
    • 244

    查看编译后的代码可以看到有get、set、equals、hashCode、canEqual、toString、无参构造方法,并没有全参构造方法
    想要全参构造方法需要添加 @AllArgsConstructor 注解。

  • 相关阅读:
    [附源码]Python计算机毕业设计Django药品仓库及预警管理系统
    【Flask】三、Flask 常见项目架构
    给电脑一键重装系统后找回照片查看器的方法
    软件开发项目保密协议
    三次握手四次挥手
    Vue中实现在线画流程图实现
    【三维重建】【SLAM】SplaTAM:基于3D高斯的密集RGB-D SLAM
    RocketMQ源码(7)—Producer发送消息源码(1)—发送消息的总体流程【一万字】
    Web基础习题
    如何正确使用 WEB 接口的 HTTP 状态码和业务状态码?
  • 原文地址:https://blog.csdn.net/weixin_46411355/article/details/127985322