<legend id='W3r0m'><style id='W3r0m'><dir id='W3r0m'><q id='W3r0m'></q></dir></style></legend>
      <bdo id='W3r0m'></bdo><ul id='W3r0m'></ul>
  • <small id='W3r0m'></small><noframes id='W3r0m'>

    <tfoot id='W3r0m'></tfoot>

      <i id='W3r0m'><tr id='W3r0m'><dt id='W3r0m'><q id='W3r0m'><span id='W3r0m'><b id='W3r0m'><form id='W3r0m'><ins id='W3r0m'></ins><ul id='W3r0m'></ul><sub id='W3r0m'></sub></form><legend id='W3r0m'></legend><bdo id='W3r0m'><pre id='W3r0m'><center id='W3r0m'></center></pre></bdo></b><th id='W3r0m'></th></span></q></dt></tr></i><div id='W3r0m'><tfoot id='W3r0m'></tfoot><dl id='W3r0m'><fieldset id='W3r0m'></fieldset></dl></div>
      1. 获取 Spring Data 上按日期排序的最后记录

        时间:2024-08-23
          <bdo id='CUyAB'></bdo><ul id='CUyAB'></ul>

            <legend id='CUyAB'><style id='CUyAB'><dir id='CUyAB'><q id='CUyAB'></q></dir></style></legend>
            <i id='CUyAB'><tr id='CUyAB'><dt id='CUyAB'><q id='CUyAB'><span id='CUyAB'><b id='CUyAB'><form id='CUyAB'><ins id='CUyAB'></ins><ul id='CUyAB'></ul><sub id='CUyAB'></sub></form><legend id='CUyAB'></legend><bdo id='CUyAB'><pre id='CUyAB'><center id='CUyAB'></center></pre></bdo></b><th id='CUyAB'></th></span></q></dt></tr></i><div id='CUyAB'><tfoot id='CUyAB'></tfoot><dl id='CUyAB'><fieldset id='CUyAB'></fieldset></dl></div>
          • <small id='CUyAB'></small><noframes id='CUyAB'>

            1. <tfoot id='CUyAB'></tfoot>

                    <tbody id='CUyAB'></tbody>

                  本文介绍了获取 Spring Data 上按日期排序的最后记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试在 Spring Data 存储库中定义一个方法,以获取按日期排序的表中的最后一条记录.这是我的实体:

                  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 {
                  
                      @Id
                      @GeneratedValue
                      private Long id;
                  
                      @Column(nullable = false)
                      private String title;
                  
                      @Column(nullable = false)
                      private String text;
                  
                      private Date publicationDate;
                  
                      /* Getters and Setters */
                  }
                  

                  这是我的存储库:

                  public interface NewsRepository extends JpaRepository<News, Long> {
                      List<News> findFirst5OrderByPublicationDateDesc();
                  }
                  

                  如果我尝试使用启动项目,我会收到下一个错误:

                  If I try to use launch the project I get the next error:

                  原因:org.springframework.data.mapping.PropertyReferenceException:否找到类型日期的属性描述!遍历路径:News.publicationDate.

                  Caused by: org.springframework.data.mapping.PropertyReferenceException: No property desc found for type Date! Traversed path: News.publicationDate.

                  如果我删除 Desc,我会得到:

                  And if I remove the Desc I get this:

                  原因:java.util.NoSuchElementException

                  Caused by: java.util.NoSuchElementException

                  我做错了什么?

                  推荐答案

                  原来方法的签名不正确.正确的是:

                  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<User> findTop10ByLastname(String lastname, Pageable pageable);
                  

                  如您所见,那里只有一个,通常的那个.

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

                  这篇关于获取 Spring Data 上按日期排序的最后记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:将 @EmbeddedId 与 JpaRepository 一起使用 下一篇:Spring Data JPA - 结果中具有多个聚合函数的自定义查询

                  相关文章

                    • <bdo id='nKfRN'></bdo><ul id='nKfRN'></ul>

                    <small id='nKfRN'></small><noframes id='nKfRN'>

                    <i id='nKfRN'><tr id='nKfRN'><dt id='nKfRN'><q id='nKfRN'><span id='nKfRN'><b id='nKfRN'><form id='nKfRN'><ins id='nKfRN'></ins><ul id='nKfRN'></ul><sub id='nKfRN'></sub></form><legend id='nKfRN'></legend><bdo id='nKfRN'><pre id='nKfRN'><center id='nKfRN'></center></pre></bdo></b><th id='nKfRN'></th></span></q></dt></tr></i><div id='nKfRN'><tfoot id='nKfRN'></tfoot><dl id='nKfRN'><fieldset id='nKfRN'></fieldset></dl></div>
                    <tfoot id='nKfRN'></tfoot>
                  1. <legend id='nKfRN'><style id='nKfRN'><dir id='nKfRN'><q id='nKfRN'></q></dir></style></legend>