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

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