Get last records ordered by date on Spring Data

后端 未结 2 1540
暖寄归人
暖寄归人 2020-12-28 13:40

I\'m trying to define a method in a Spring Data repository to fetch the last records on a table ordered by date. This is my entity:

@Entity
public class News         


        
2条回答
  •  -上瘾入骨i
    2020-12-28 14:04

    Turns out that the signature of the method was incorrect. The right one is:

    findFirst5ByOrderByPublicationDateDesc()
    

    Is a little confusing because in the official samples they have this:

    List findTop10ByLastname(String lastname, Pageable pageable);
    

    As you can see there is only one By there, the usual one.

提交回复
热议问题