Spring boot api列表分页

当我们使用org.springframework.data.domain.PageRequest对列表数据分页时候,返回的数据不包含总页数totalPages这些数据。

如果我们直接让方法返回org.springframework.data.domain.Page<T>。

//import org.springframework.data.domain.Page;

@GetMapping(consumes = "application/json")
public Page<Ingredient> index(@PageableDefault Pageable pageable) {
Page<Ingredient> page = this.ingredientRepository.findAll(pageable);
log.info(page.getClass().getCanonicalName());
return page;
}

  

原文地址:https://www.cnblogs.com/fengliang/p/14273490.html