sqlite 实现分页排序
版本号
MacOS Apple M1 | Jdk17 | Maven 3.8.5 | SpringBoot 2.6.9 | 内嵌式 Sqlite 3.42.0.0
Pageable 使用方式
findAll()
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
// 根据 score 字段升序分页
Pageable pageable = PageRequest.of(current, pageSize, Sort.by(Sort.Direction.ASC, "score"));
// Student 为自定义 entity
Page<Student> page = scriptsRepository.findAll(pageable);
自定义查询
@Repository
public interface ScriptRelatedTablesRepository extends JpaRepository<User, Long> {
@Query("select u from User u where u.id <= ?1")
Page<User> findWithPage(Long id, Pageable pageable);
}
本文来自博客园,作者:这个杀手冷死了,转载请注明原文链接:https://www.cnblogs.com/pandacode/p/17644155.html