In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you what are the findBy grammar rules in JPA, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
The difference between all findBy Syntax Rule 1 and findBy findAllBy in JPA
There is no difference between them, they will execute exactly the same query, and when the query is derived from the method name, Spring Data ignores the All part. The only thing that matters is the By keyword, anything that follows it is treated as a field name
For example, findXXXXXXXXXXXXXByName actually = "findByName"
2. Keywords supported in 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); but it is important to note that% we need to write it ourselves.
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.
JPA findBy syntax summary 1. JPA queries two attributes at the same time.
One of them is the property of embedded class
FindByIdageAndTime (int age, Date time) 2, table summary
3. When the Spring Data JPA framework parses the method name
It will first truncate the redundant prefixes of the method name, such as find, findBy, read, readBy, get, getBy, and then parse the rest.
4. NamedQueries of JPA
Use @ NamedQuery on entity classes. Examples are as follows:
@ NamedQuery (name = "UserModel.findByAge", query = "select o from UserModel o where o.age > =? 1")
Define a method with the same name in the Repository API of the self-implemented DAO. The example is as follows:
Public List findByAge (int age)
Then it can be used. Spring will first find out whether there is a NamedQuery with the same name, and if so, it will not be parsed according to the method defined by the interface.
5. JPQL query @ Query ("from SysUser u where u.nickname=:nickname") SysUser findUser (@ Param ("nickname") String nickname); @ Query ("from SysUser u where u.nickname like%: nickname% order by u.fans desc") List findUsers (@ Param ("nickname") String nickname). This is all the content of the article "what are the findBy grammar rules in JPA?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.