Spring Boot, MySQL, JPA, Restful API Derived Methods Example Part-1
If you don't know how to set base project
Please follow the spring boot tutorial
spring-boot link :
• EP-1a spring boot hello world example...
Channel lnk : / @gk-care
Link in description
? - How to retrieve data from Non-Primary Key
If we want to retrieve data apart from the Primary Key Column,
than first approach will be the Derived Method approach.
Spring Boot automated this concept. The developer can write only abstract method i.e. only method signature without any implementation(only definition) and the entire implementation will be taken care by Spring boot
Derived Method Concept: To retrieve data
needs to follow some rules in the process to define methods
1) The "findBy" keyword is a prefix.
2) should be append property name( entitiy-variable-name) followed by prefix.
3) The method name should be in camel case format
example: findByEmail(String email),
@Entity
@Table(name="tbl_employee")
public class Employee {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="emp_id")
private Integer empId;
private String name;
private String email;
.
.
.
}
Note: There are many ways to use the "Derived method" like "findBy" as I Explained
"deleteBy", "countBy"
Use this link "https://docs.spring.io/spring-data/jp..." to check it
Derived Query Methods in Spring Data JPA Repository
Derived Queries with Spring Data JPA
Spring Boot Data JPA-derived queries
Spring Data JPA Derived Query Methods Example
Custom Finder method Derived Query method in Spring boot
How Does Spring JPA Derive Query
The Best way to use Spring Data query methods