SoFunction
Updated on 2025-03-03

SpringBoot lombok (annotation @Getter @Setter) Detailed explanation

SpringBoot lombok(Annotation @Getter @Setter)

Using lombok annotation, setter/getter and other methods will exist in the compiled bytecode files, reducing the amount of code and facilitating code maintenance

Add dependencies

<dependency>
    <groupId></groupId>
    <artifactId>lombok</artifactId>
    <scope>provided</scope>
</dependency>

How to use

  • @Setter @Getter: Can be automatically generated for the corresponding attributesGetter/Settermethod
  • @Data: Will automatically generate all attributes of the classsetter/getterequalscanEqualhashCodetoStringmethod. If it is a final property, a setter method will not be generated for the property.
import .*;
import ;

@Data
@Entity
@Table(name = "student")
public class Student {
    @Id
    @Column(name = "id")
    @GeneratedValue(strategy = )
    private long id;

    @Column(name = "name")
    private String name;

    @Column(name = "email")
    private  String email;


    @Column(name = "age")
    private  int age;
}

Summarize

The above is personal experience. I hope you can give you a reference and I hope you can support me more.