Spring Data JPA Method Definition Specification

Source: Internet
Author: User
Tags uuid

rules defined by the Spring Data JPA method:  

(1) Simple condition query

Simple conditional query: Queries an entity class or collection.

In accordance with the specifications of Spring data, the query method begins with a Find | read | Get , and when the query condition is involved, the properties of the condition are connected with the Conditional keyword, note that the conditional attribute is capitalized in the first letter.

For example, define a class of entity entities:

classpeople{       private String firstName;       Private String LastName;}

this should be written when querying with and conditions above:findbylastnameandfirstname (stringlastname,string firstName);

Note: The property name and number of the condition should correspond to the position of the parameter one by one

(2) supported keywords

Directly in the interface to define the query method, if it is compliant, can not write implementation, the currently supported keywords are as follows:

(3) Query method parsing process

If we create a query like this:Findbyuserdepuuid (), when the framework parses the method, it first rejects the findBy and then parses the remaining attributes, assuming the query entity is Doc.

1. First Judge Userdepuuid (according to POJO (Plain Ordinary Java object Simple Java objects, is actually ordinary java Bean) specification, the first letter becomes lowercase. is a property of the query entity, and if the query is based on that property, the second step continues if there is no attribute.

2. Truncate the string starting from right to left ( Uuid here), then check if the remaining string is a property of the query entity, or, if it is, a query based on that property, and if it does not, repeat the second step and continue from right to left; user is a property of the query entity.

3. Then processing the remainder (depuuid), first determine whether the user's corresponding type has a depuuid attribute, if any, it means that the method is ultimately based on thevalue of "Doc.user.depUuid" query Otherwise, continue to intercept from right to left according to the rules of step 2, which ultimately indicates a query based on thevalue of "Doc.user.dep.uuid".

4. There may be a special case, such as doc contains a user attribute, there is also a USERDEP property, there is confusion. You can explicitly add "_" between attributes to explicitly express an intent, such as "Findbyuser_depuuid ()" or "Findbyuserdep_uuid ()".

Special parameters: You can also add paging or sorting parameters directly to the parameters of the method, such as:

Page<usermodel>findbyname (String name, pageable pageable);

List<usermodel>findbyname (String name, sort sort);

Spring Data JPA Method Definition Specification

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.