Spring boot

Data annotations using Spring Boot

In this tutorials will teach you @AllArgsConstructor and @NoArgsConstructor @Data annotations.what is the purpose we use this annotations is if we have a class it has Argument Constructor and No Argument Constructor and Getter and Setters and String Method. instead of implementing all of these.


simply  implementing these annotations this can manage by all the works.

i have attached two examples

Example 1

this example we implemented the Argument Constructor and No Argument Constructor and Getter and Setters and String Method.

public class EmployeeUpdateRequestDTO {

    private int employeeId;
    private String employeeName;
    private String employeeAddress;
    private double employeeSalary;
    private ArrayList contactNumbers;
    private String nic;
    private boolean activeState;


    public EmployeeUpdateRequestDTO(int employeeId, String employeeName, String employeeAddress, double employeeSalary, ArrayList contactNumbers, String nic, boolean activeState) {
        this.employeeId = employeeId;
        this.employeeName = employeeName;
        this.employeeAddress = employeeAddress;
        this.employeeSalary = employeeSalary;
        this.contactNumbers = contactNumbers;
        this.nic = nic;
        this.activeState = activeState;
    }

    public EmployeeUpdateRequestDTO() {
    }

    public int getEmployeeId() {
        return employeeId;
    }

    public void setEmployeeId(int employeeId) {
        this.employeeId = employeeId;
    }

    public String getEmployeeName() {
        return employeeName;
    }

    public void setEmployeeName(String employeeName) {
        this.employeeName = employeeName;
    }

    public String getEmployeeAddress() {
        return employeeAddress;
    }

    public void setEmployeeAddress(String employeeAddress) {
        this.employeeAddress = employeeAddress;
    }

    public double getEmployeeSalary() {
        return employeeSalary;
    }

    public void setEmployeeSalary(double employeeSalary) {
        this.employeeSalary = employeeSalary;
    }

    public ArrayList getContactNumbers() {
        return contactNumbers;
    }

    public void setContactNumbers(ArrayList contactNumbers) {
        this.contactNumbers = contactNumbers;
    }

    public String getNic() {
        return nic;
    }

    public void setNic(String nic) {
        this.nic = nic;
    }

    public boolean isActiveState() {
        return activeState;
    }

    public void setActiveState(boolean activeState) {
        this.activeState = activeState;
    }

    @Override
    public String toString() {
        return "EmployeeUpdateRequestDTO{" +
                "employeeId=" + employeeId +
                ", employeeName='" + employeeName + '\'' +
                ", employeeAddress='" + employeeAddress + '\'' +
                ", employeeSalary=" + employeeSalary +
                ", contactNumbers=" + contactNumbers +
                ", nic='" + nic + '\'' +
                ", activeState=" + activeState +
                '}';
    }

Example 2

instead of implementing all of these just write these annotations. These annotations this can manage by all the works.

if you want add these annotations you have to add the maven lombok dependency.click here  
to add these dependency on the pom.xml file.

@AllArgsConstructor and @NoArgsConstructor @Data annotations

@AllArgsConstructor
@NoArgsConstructor
@Data
public class EmployeeUpdateRequestDTO 
{
    private int employeeId;
    private String employeeName;
    private String employeeAddress;
    private double employeeSalary;
    private ArrayList contactNumbers;
    private String nic;
    private boolean activeState;
}

i have attached the video link below. which will do this tutorials step by step

 

admin

Recent Posts

Registration with image upload Java Jdbc(Download Source code)

Introduction In this section, we will guide you step by step in the development of an image upload registration system in Java using MySQL and JDBC. In the application, users register…

3 weeks ago

Touchable shop Pos system using Java

The Touchable Shop POS (Point of Sale) system is a sophisticated software solution developed using…

1 month ago

Build Your First Responsive Login Form Using HTML and CSS FlexBox

Creating a responsive login form is a crucial skill for any web developer. In this…

1 month ago

Build Crud API with Laravel 12

In this tutorial will teach  Laravel 12 CRUD API  by step. Laravel  10 CRUD Application …

2 months ago

laravel 12 image upload tutorial

In this lesson we talk about laravel 12 image uploading and display the image step…

2 months ago

Laravel 12 CRUD Application

In this tutorial will teach Laravel 12 CRUD Application step by step. Laravel  12 CRUD…

2 months ago