Java 如何从服务返回小块数据
我希望在每个客户端请求中返回一小块数据。假设每个请求上有100个项目。这是我的服务端控制器代码-Java 如何从服务返回小块数据,java,spring,spring-mvc,spring-data,Java,Spring,Spring Mvc,Spring Data,我希望在每个客户端请求中返回一小块数据。假设每个请求上有100个项目。这是我的服务端控制器代码- @RequestMapping(value = "/find/customerrequestv2byperiod", method = RequestMethod.GET, produces = "application/json") @ResponseBody public List<CustomerRequestV2> findCustomerReq(@Request
@RequestMapping(value = "/find/customerrequestv2byperiod", method = RequestMethod.GET,
produces = "application/json")
@ResponseBody
public List<CustomerRequestV2> findCustomerReq(@RequestParam(value = "id") final String pId,
@RequestParam(value = "datetperiod") final String pdatetPeriod)
{
List<CustomerRequestV2> requestList = null;
try
{
requestList = requestService.findCustomerReq(pProductId, pReceiptPeriod);
}
catch (final ServiceException e)
{
LOG.error(ERROR_RETRIEVING_LIST + pProductId, e);
}
return requestList;
}
@RequestMapping(value=“/find/customerrequestv2byperiod”,method=RequestMethod.GET,
products=“application/json”)
@应答器
公共列表findCustomerReq(@RequestParam(value=“id”)最终字符串pId,
@RequestParam(value=“datePeriod”)最终字符串pdatePeriod)
{
List requestList=null;
尝试
{
requestList=requestService.findCustomerReq(pProductId,PreciptPeriod);
}
捕获(最终服务异常e)
{
LOG.error(检索列表时出错+pProductId,e);
}
返回请求列表;
}
此处requestList包含与此查询匹配的数据列表。因为有时候它一次运行500多个数据。客户端am使用angular.js。所以我只是想在请求本身中发送一些偏移量值,但是如何从这里返回一小块数据呢?if(requestList==null | | offset>requestList.size())返回新的ArrayList();
if(requestList == null || offset > requestList.size()) return new ArrayList<CustomerRequestV2>();
int numberOfItems = 100;
int fromIndex = offset;
int toIndex = Math.min(offset+numberOfItems, requestList.size());
return requestList.subList(fromIndex, toIndex);
int numberOfItems=100;
int fromIndex=偏移量;
int-toIndex=Math.min(offset+numberOfItems,requestList.size());
返回请求列表。子列表(从索引到索引);
根据偏移量制作子列表并发送..根据您的要求尝试使用子列表的可能重复项。下面是有关列表上的子列表的详细信息的链接。