您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

如何在Spring Data中将OrderBy与findAll一起使用

如何在Spring Data中将OrderBy与findAll一起使用

public interface StudentDAO extends JpaRepository<StudentEntity, Integer> {
    public List<StudentEntity> findAllByOrderByIdAsc();
}

上面的代码应该可以工作。我正在使用类似的东西:

public List<Pilot> findTop10ByOrderByLevelDesc();

它返回最高级别的10行。

重要提示: 由于有人告诉我很容易错过此答案的关键点,因此需要澄清一下:

findAllByOrderByIdAsc(); // don't miss "by"
Java 2022/1/1 18:17:47 有481人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶