Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement OrderBy by findAll in Spring DATA JPA

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces the Spring DATA JPA findAll how to carry out OrderBy, the article is very detailed, has a certain reference value, interested friends must read it!

FindAll in Spring DATA JPA for OrderBy

You need to define such a method in repository: findAllByOrderByUpdatedAtDesc ()

Public List findAllByOrderByUpdatedAtDesc ()

Important: (add an extra By in the middle)

FindAllByOrderByUpdatedAtDesc ()

The little 'By' does all the magic.

Spring Data JPA uses a small pit of orderby.

According to the JPA writing method that can be found on the Internet, I want to find all the data and arrange them in ascending order of rank. The code is as follows.

Public interface RsEventRepository extends CrudRepository {List findAllByOrderByRankAsc ();}

As a result, java reported an error, and then looked for problems in entity and repository.

Java.lang.IllegalStateException: Failed to load ApplicationContext

No property asc found for type int! Traversed path: RsEventEntity.rank.

Finally, it was found that a by should be added after ALL.

List findAllByOrderByRankAsc ()

In this way, I can make an inquiry according to my idea.

The above is all the content of the article "how to OrderBy findAll in Spring DATA JPA". Thank you for reading! Hope to share the content to help you, more related 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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report