Spring Data JPA使用findAllOrderBy時踩的坑


Spring Data JPA使用findAllOrderBy時踩的坑

按照以往的編程經驗,我的寫法是這樣的:

    List<ActivityEntity> findAllOrderByWishCountDesc();

可以看到,我希望在一個表中查詢所有的數據,並按照WishCount這個字段進行排序,這樣的寫法看似正確的,但總會報這樣的錯誤:

Caused by: java.lang.IllegalArgumentException: Failed to create query for method public abstract    java.util.List com.obowin.sports.business.activity.ActivityRepository.findAllOrderByWishCountDesc()! No property desc found for type Integer! Traversed path: ActivityEntity.wishCount.
Caused by: org.springframework.data.mapping.PropertyReferenceException: No property desc found for type Integer! Traversed path: ActivityEntity.wishCount.

其實,正確的寫法是:

    List<ActivityEntity> findAllByOrderByWishCountDesc();

需要在findAll后面再加上一個By,這樣才可以查詢到想要的數據,真的令人吐血。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM