In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article is about how JPA uses the findBy method to customize queries. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
JPA uses the findBy method to customize the query
Recently, spring boot+jpa has been used in the project to access the database. For example, the foreign key course details ID is included in the course catalogue details table in this project. You want to find out all the related course catalog details through the course details ID.
Use findBy method to customize query in JPA
The interface for testing the request in postman is as follows
In this way, it is very convenient to query the required data without having to write the interface to filter it.
FindBy syntax collation prerequisite operation of JPA
Create a persistent entity class
Dao layer inherits JpaRepository
T: entity class
ID: the primary key type of the entity class
Example:
Keywords supported in public interface SysUserRespository extends JpaRepository {} JPA
And: equivalent to the and keyword in SQL, such as findByUsernameAndPassword (String user, Striang pwd)
Or: equivalent to the or keyword in SQL, such as findByUsernameOrAddress (String user, String addr)
Between: equivalent to the between keyword in SQL, such as findBySalaryBetween (int max, int min)
LessThan: equivalent to "" in SQL, such as findBySalaryGreaterThan (int min)
IsNull: equivalent to "is null" in SQL, such as findByUsernameIsNull ()
IsNotNull: equivalent to "is not null" in SQL, such as findByUsernameIsNotNull ()
NotNull: equivalent to IsNotNull
Like: equivalent to "like" in SQL, such as findByUsernameLike (String user)
NotLike: equivalent to "not like" in SQL, such as findByUsernameNotLike (String user)
OrderBy: equivalent to "order by" in SQL, such as findByUsernameOrderBySalaryAsc (String user)
Not: equivalent to "! =" in SQL, such as findByUsernameNot (String user)
In: equivalent to "in" in SQL, such as findByUsernameIn (Collection userList). The parameters of the method can be of type Collection, array or indefinite length.
NotIn: equivalent to "not in" in SQL, such as findByUsernameNotIn (Collection userList). The parameters of the method can be of type Collection, array or indefinite length.
Thank you for reading! On "JPA how to use findBy method custom query" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, you can share it out for more people to see it!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.