Hi guys✋,This is day 15 of landing a Job in 30days👩💻.
Learned about Record
public class EmployeeDetails{
private int id ;
private String name;
public class EmployeeDetails(int id,String name){
this.id=id;
this.name=name;
}
//Getter and Setter
//toString and hashcode
@Override
public String toString(){
return "EmployeeDetails(name=" + this.getName() +", employeeId=" + this.id")";
}
}
public class Employee{
public static void main(String[] args){
EmployeeDetails employee = new EmployeeDetails(1,"Ram");
//record
EmployeeRecord employeeRecord = new EmployeeRecord(2,"Raj");
}
}
//Record
public record EmployeeRecord (int id, String name){
}
Records are immutable data classes that require only the type and name of fields.
The record has default constructor with the arguments .
We can implement interface but we cannot use extend in it.
Since the record is immutable there is no setter.
I tired to create a ToDo app using Springboot and recalled few things.
Package uses in springboot
Entity -- To store the data in table
Repository -- Spring Data JPA repositories are interfaces with methods supporting creating, reading, updating, and deleting records against a back end data store.
Service -- Define the contract and business logic for managing To-Do items. The implementation utilizes Spring Data JPA and the repository
to interact with the database
Controller -- Responsible for processing incoming REST API requests, preparing a model, and returning the view to be rendered as a response.