场景:
本系统用的Mybatis分页插件PageHelper,调用了外部系统返回的数据为String类型的JSON串,数据量毕竟多,界面需要分页展示。
解决思路:
返回数据转List,然后把多个List放到一个List里,然后在从这个List里进行分页,前端只需要传一个页码过来即可,
部分代码如下:
Service代码
ResponseMsg<AppResp> responseMsg = new ResponseMsg<>();
int currentPage = req.getCurrentPage();int pageSize = req.getPageSize();
String str= "[{"id":1546051323216,"name":"TPCE测试流程"},{"id":1546051343822,"name":"TPC-DS测试流程"}]";//例子
List list = JSONArray.parseArray( str );
List<Object> objects = new ArrayList<>();int num = (currentPage > 1 ? (currentPage - 1) * pageSize : 0);assert list != null;for (int i = 0; i < pageSize && i < list.size() - num; i++) { objects.add( list.get( num + i ) );}
AppResp appResp = new AppResp();appResp.setList( objects );responseMsg.setResult( appResp );responseMsg.setCurrentPage( currentPage );responseMsg.setTotal( list.size() );
js代码:
$scope.list = [];$scope.currentPage = 1;$scope.pageSize = 10;$scope.getProcessList = function () { PARAM_BODY.currentPage = $scope.currentPage; PARAM_BODY.pageSize = $scope.pageSize; $http({ method: ‘POST‘, url: options.app_api + ‘/app/getProcessList‘, data: JSON.stringify(PARAM_BODY) }).success(function (data) { $scope.list = data.result.list; $scope.currentPage = data.currentPage; $scope.total = data.total; });};
原文地址:https://www.cnblogs.com/misterzhaoyan/p/10335386.html
时间: 2024-11-05 12:31:47