JPA原生SQL(自定义SQL)分页查询逻辑

JPA自己写SQL查询的话,分页还稍微麻烦,经过测试下面方法可以:

@Query(nativeQuery = true, value = "select * from goods where " +
            " codeName like CONCAT('%',?1,'%') and order by  ?w#{#pageable}")
    Page<Goods> findByName(String name, Pageable pageable);

pageable对象里定义排序的字段:

Pageable pageable = new PageRequest(pageNumber, pageSize,Sort.Direction.DESC, "id");

 

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 创作都市 设计师:CSDN官方博客 返回首页