In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.