Reputation: 1571
In have JPARepository and I create a method to get data by KeyWord:
That is my interface:
@Query(value="select p from Poeple p where name like :x")
public Page<Poeple> searchByMc(@Param( value = "x")String mc, Pageable pageable );
In my Service I receive Request and call this method like that:
@RequestMapping(value="/poeples", method=RequestMethod.GET)
public Page<Poeple> listPoeples(@RequestParam(name="mc") String mc, @RequestParam(name="page", defaultValue="0" ) int page, @RequestParam(name="size", defaultValue="5" )int size){
mc = "%"+ mc + "%";
return poepleRepository.searchByMc(mc, new PageRequest(page, size,new Sort(Sort.Direction.ASC, "name")));
}
My problem is that when i have just one or two result my Response content the TotalContent But the content array don't have any data.
I call this Class from my Angular App, looked like that :
var myApp = angular.module('myApp',[]);
myApp.controller('PoepleController', function($scope, $http) {
$scope.mc = '';
$scope.poeples = [];
$scope.page=1;
$scope.size=10;
$scope.SearchPoeple = function(){
$http.get("http://localhost:8080/poeples?page="+ $scope.page+"&size="+$scope.size+"&mc="+$scope.mc)
.then(function(data){
$scope.poeples = data.data.content;
}, function(err){
console.log(err);
});
}
});
That is my response:
{content: [], last: true, totalPages: 1, totalElements: 3, size: 10, number: 1, first: false,…}
content
:
[]
first
:
false
last
:
true
number
:
1
numberOfElements
:
0
size
:
10
sort
:
[{direction: "ASC", property: "name", ignoreCase: false, nullHandling: "NATIVE", ascending: true,…}]
totalElements
:
3
totalPages
:
1
Like you can see I have 3result but the content array is empty.
Thanks
Upvotes: 0
Views: 852
Reputation: 1571
I found the solution, I let the question because I think that some beginner like me can make the mistake:
The first page is the page 0
Like we can see in my response I had result first : false
Because We have to correct in the Angular Code
$scope.page = 0
I hope this can help!
Upvotes: 2