IDEA之lombok插件

我就是我 2024-04-17 14:07 166阅读 0赞

Java 实体类自动生成get set!

1.idea Ctrl+Alt+S 先配置上lombok插件,如图:

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2thbmd6aHVhbmc1MjE_size_16_color_FFFFFF_t_70

2.pom.xml中引入依赖,如图:

20190827104437329.png

3.实体类上添加@Data,如图:

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2thbmd6aHVhbmc1MjE_size_16_color_FFFFFF_t_70 1

4.看.class文件,get set toString 方法都会有。

  1. package com.example.domain;
  2. public class Users {
  3. private String id;
  4. private String name;
  5. private String age;
  6. public Users() {
  7. }
  8. public String getId() {
  9. return this.id;
  10. }
  11. public String getName() {
  12. return this.name;
  13. }
  14. public String getAge() {
  15. return this.age;
  16. }
  17. public void setId(String id) {
  18. this.id = id;
  19. }
  20. public void setName(String name) {
  21. this.name = name;
  22. }
  23. public void setAge(String age) {
  24. this.age = age;
  25. }
  26. public boolean equals(Object o) {
  27. if (o == this) {
  28. return true;
  29. } else if (!(o instanceof Users)) {
  30. return false;
  31. } else {
  32. Users other = (Users)o;
  33. if (!other.canEqual(this)) {
  34. return false;
  35. } else {
  36. label47: {
  37. Object this$id = this.getId();
  38. Object other$id = other.getId();
  39. if (this$id == null) {
  40. if (other$id == null) {
  41. break label47;
  42. }
  43. } else if (this$id.equals(other$id)) {
  44. break label47;
  45. }
  46. return false;
  47. }
  48. Object this$name = this.getName();
  49. Object other$name = other.getName();
  50. if (this$name == null) {
  51. if (other$name != null) {
  52. return false;
  53. }
  54. } else if (!this$name.equals(other$name)) {
  55. return false;
  56. }
  57. Object this$age = this.getAge();
  58. Object other$age = other.getAge();
  59. if (this$age == null) {
  60. if (other$age != null) {
  61. return false;
  62. }
  63. } else if (!this$age.equals(other$age)) {
  64. return false;
  65. }
  66. return true;
  67. }
  68. }
  69. }
  70. protected boolean canEqual(Object other) {
  71. return other instanceof Users;
  72. }
  73. public int hashCode() {
  74. int PRIME = true;
  75. int result = 1;
  76. Object $id = this.getId();
  77. int result = result * 59 + ($id == null ? 43 : $id.hashCode());
  78. Object $name = this.getName();
  79. result = result * 59 + ($name == null ? 43 : $name.hashCode());
  80. Object $age = this.getAge();
  81. result = result * 59 + ($age == null ? 43 : $age.hashCode());
  82. return result;
  83. }
  84. public String toString() {
  85. return "Users(id=" + this.getId() + ", name=" + this.getName() + ", age=" + this.getAge() + ")";
  86. }
  87. }

发表评论

表情:
评论列表 (有 0 条评论,166人围观)

还没有评论,来说两句吧...

相关阅读

    相关 IDEA集成Lombok

    安装这个lombok插件后会节省不少代码量,使用最多的地方就是简化了get/set方法,让代码看起来更加简洁。 1.首先我们需要安装IntelliJ IDEA中的lombo

    相关 Idea下安装lombok

          lombok是一个可以通过简单的注解的形式来帮助我们简化消除一些必须有但显得很臃肿的 Java 代码的工具,简单来说,比如我们新建了一个类,尤其是遇到实体类有很多属

    相关 IntelliJ IDEA lombok

    IntelliJ IDEA是一款非常优秀的集成开发工具,功能强大,而且插件众多。lombok是开源的代码生成库,是一款非常实用的小工具,我们在编辑实体类时可以通过lombok注