dao
一般的查询语句里面 可以没有 select 直接from 实体类 但用分页则一定要有select
@Query("select d from BceReceipt d where ausit=0")
Page<BceReceipt> jhdlist(Pageable pageable);
返回数据也不用List了,直接用Page接了,括号里面的条件一定要记得,Pageable 不能漏,带进来的页数,真分页的查询
service
这边的话要给controller注入 所以返回值需要时List 同时,p参数里面吧paga打上即可
List<BceReceipt> jhdlist(int page);
serviceimpl
注入的dao实现了service 所以返回值是List 参数controller 那边来的,需要一个转换的过程 如下
@Override
public List<BceReceipt> jhdlist(int page) {
Pageable pageable=new PageRequest(page, 10);
Page<BceReceipt> page2=bceReceiptDao.jhdlist(pageable);
return page2.getContent();
}
Sort sort = new Sort(Direction.DESC, "id");
Pageable pageable = new PageRequest(page, size, sort);
page,第几页,从0开始,默认为第0页
size,每一页的大小,默认为20
sort,排序相关的信息,以property,property(,ASC|DESC)的方式组织,例如sort=firstname&sort=lastname,desc表示在按firstname正序排列基础上按lastname倒序排列
controller
直接传page就行了
@RequestMapping("jhdlist") public void jhdlist(HttpServletResponse response) throws IOException, ParseException{ List<BceReceipt> jhdlist = bceReceiptService.jhdlist(0); RenderUtil.renderJson(jhdlist, response); }
后台的一个流程就这样的额