我正在使用 spring 数据,我的 DAO 看起来像
public interface StudentDAO extends JpaRepository<StudentEntity, Integer> {
public findAllOrderByIdAsc(); // I want to use some thing like this
}
在上面的代码中,注释行显示了我的意图。 spring Data 可以提供内置功能吗
使用这样的方法来查找所有记录按某个列按 ASC/DESC 排序?
public interface StudentDAO extends JpaRepository<StudentEntity, Integer> {
public List<StudentEntity> findAllByOrderByIdAsc();
}
上面的代码应该可以工作。我正在使用类似的东西:
public List<Pilot> findTop10ByOrderByLevelDesc();
它返回 10 行最高级别。
重要的:因为我被告知很容易错过这个答案的关键点,所以这里有一点澄清:
findAllByOrderByIdAsc(); // don't miss "by"
^
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)