试试这种方式:
findAll方法带参数"PageRequest()"提供服务器端分页
有两种方法
PageRequest(int page,int size)
PageRequest(int page,int size,Direction direction,String ... properties)
查看:
DispatureServiceHostValue
{{x.dispature}}{{x.service}}{{x.host}}{{x.value}}total-items="app.totalItems" boundary-link-numbers="true"
ng-model="app.currentPage" rotate="false" max-size="app.maxSize"
class="pagination-sm" boundary-links="true"
ng-click="app.getPagableRecords()">
Page: {{app.currentPage}} / {{numPages}}
Js控制器:
app.controller('AllEntryCtrl',['$scope','$http','$timeout','$rootScope', function($scope,$http,$timeout,$rootScope){
var app = this;
app.currentPage = 1;
app.maxSize = 5;
app.itemPerPage = 5;
app.totalItems = 0;
app.countRecords = function() {
$http.get("countRecord")
.success(function(data,status,headers,config){
app.totalItems = data;
})
.error(function(data,status,header,config){
console.log(data);
});
};
app.getPagableRecords = function() {
var param = {
page : app.currentPage,
size : app.itemPerPage
};
$http.get("allRecordPagination",{params : param})
.success(function(data,status,headers,config){
app.metricsList = data.content;
})
.error(function(data,status,header,config){
console.log(data);
});
};
app.countRecords();
app.getPagableRecords();
}]);
控制器:
@RestController
public class HomeController {
@Autowired
private HomeRepo repo;
@RequestMapping(value = "allRecordPagination", method = RequestMethod.GET)
public Page getAllRecordPagination(@RequestParam("page") int page, @RequestParam("size") int size){
return repo.findAll(new PageRequest(page-1, size));
}
}
存储库:
@Repository
public interface HomeRepo extends JpaRepository
}