MogoDB实现根据条件查询进行分页返回
1、Repository:
@Repository public interface DeviceRepository extends MongoRepository<Device, String> { @Query(“{‘deviceId’:’?0′}”) //注解拿开就是根据id查询并分页,如果多个条件根据json格式来写多个,如 {‘id’:’?0′,’name’:’?1′} |
2、实际中使用,Controller
@RequestMapping(“device/findByPage”) public Page<Device> findDevicePage( @RequestParam(value = “page”, defaultValue = “1”) Integer pageNo, @RequestParam(value = “size”, defaultValue = “6”) Integer size) { PageRequest request = new PageRequest(pageNo, size); Page<Device> page=deviceService.findAllByDeviceId(request,”001″); //id 没有使用 return page; }
|
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。