From the course: Creating Spring Boot Microservices
Unlock the full course today
Join today to access over 24,900 courses taught by industry experts.
Introduction to Spring Data query methods - Spring Boot Tutorial
From the course: Creating Spring Boot Microservices
Introduction to Spring Data query methods
- [Instructor] For general purpose database lookups, the built-in find all and find one repository methods are sufficient. But what do we do if we want to look up all easy tours or all tours less than $800 or both, do we have to create ugly SQL scripts? No, spring data property expressions to the rescue. We just de declare methods for our JPA repository interface, then via bean utils reflections and generics, spring data implements the method under the covers for us. However, we must follow the syntax rules when declaring methods and correctly map the entity properties to the method signatures. So these are the rules when using property expressions to query for entities. First, we have to declare the return type for a single value. It can be the actual class or an optional of it. For multiple, a collection. Then you need to begin the method signature with findBy, followed by the property name in camel case. Optionally, chain sub property names following camel case rules. For example…
Contents
-
-
-
-
-
(Locked)
The domain model2m 9s
-
(Locked)
The persistence entities2m 2s
-
(Locked)
Declare JPA repositories4m 36s
-
(Locked)
Spring Data JPA repository dependency injection3m 48s
-
(Locked)
Invoking the repositories7m 33s
-
(Locked)
Introduction to Spring Data query methods3m 2s
-
(Locked)
Challenge: Create a JPQL query method38s
-
(Locked)
Solution: Create a JPQL query method2m 35s
-
(Locked)
-
-
-
-
-
-
-