【发布时间】:2016-05-30 03:36:20
【问题描述】:
我正在尝试在服务中实现分页。使用 Cassandra 作为数据库 如果查询返回少量列表,我的代码可以正常工作。我只是过滤掉页数[硬编码为 100/不想硬编码而是作为参数返回] 和偏移值。因此,对于每个请求,我都不想进行查询。确信应该有一种可能的方法来设置查询本身的偏移值。 我的代码-
@RequestMapping(value = "/find/customerreqbyperiod", method = RequestMethod.GET,
produces = "application/json")
@ResponseBody
public List<CustomerReq> findCustomerRequest(@RequestParam(value = "productid") final String pProductId,
@RequestParam(value = "dataperiod") final String pdataPeriod,
@RequestParam(value = "offset") final int offset)
{
List<CustomerReq> requestList = null;
try
{
requestList = requestService.findCustomerRequest(pProductId, pdataPeriod, offset);
if (requestList == null || offset > requestList.size()) return new ArrayList<CustomerRequestV2>();
int numberOfItems = 10;
int fromIndex = offset;
int toIndex = Math.min(offset + numberOfItems, requestList.size());
return requestList.subList(fromIndex, toIndex);
}
catch (final ServiceException e)
{
LOG.error(ERROR_RETRIEVING_LIST + pProductId, e);
}
return requestList;
}
@Repository-
@Query("select * from customer_request where product_id = ?0 and data_period = ?1")
List<CustomerReq> findByProductIdAnddataPeriod(String productId, String dataPeriod, int offset);
请提供您宝贵的建议。谢谢!-Saurav
【问题讨论】:
标签: java spring pagination cassandra spring-data