sprintboot分页查询mongodb

  1. 在interface中定义
    public interface LoginLogRepository extends MongoRepository{
    Page findByUserid(String userid, Pageable page);
    }
  2. 直接使用pageable接收参数
    public Page actpage(@RequestParam String userid,
    @PageableDefault(value = 2, sort = { "logintime" }, direction = Sort.Direction.DESC) Pageable pageable) {
    ServiceInstance instance = client.getLocalServiceInstance();
    Page log = loginLogRepository.findByUserid(userid, pageable);
    logger.info("/act, host:" + instance.getHost() + ", service_id:" + instance.getServiceId() + ", result:" + log.getSize());
    return log;
    }

你可能感兴趣的:(sprintboot分页查询mongodb)