0

我在服务器端有方法:

@RequestMapping(method = RequestMethod.GET)
public List<UserDTO> getAllUsers(@RequestParam(value = "groupId", required = false) Long groupId,
                                 @RequestParam(value = "pagination") Pagination pagination){
    // some stuff
}

我尝试从客户端发送数据Restangular

function getUsers(filters){
    restService.all("users").getList(filters).then(function(users){
        $scope.data.users = users;
    });
}
// ....
getUsers({groupId: undefined, pagination: $scope.data.pagination});

pagination可以在哪里:

$scope.data = {
    // Other parameters
    pagination: {
        currentPage: 1,
        totalItems: 30,
        itemsPerPage: 5
    }
};

但我得到了:

Failed to convert value of type 'java.lang.String' 
to required type 'pagination.Pagination';

当我寻找时,Request URL我看到:

http://localhost:8080/skp/users?pagination=%7B%22currentPage%22:1,%22totalItems%22:30,%22itemsPerPage%22:5%7D

并且Query String Parameters是:

pagination:{"currentPage":1,"totalItems":30,"itemsPerPage":5}

我希望应该将分页对象发送到服务器端,但它尝试发送字符串而不是对象。是否知道如何使用 HTTPGET方法和getList Restangular方法发送参数不是 as Query String,我认为这会导致我的问题?或者如何让服务器端将其视为Pagination对象,而不是字符串?非常感谢您的回答

4

1 回答 1

1
pagination=%7B%22currentPage%22:1,%22totalItems%22:30,%22itemsPerPage%22:5%7D

正如我的评论中所述,这是一个值为字符串的参数。如果您希望在服务器端填充对象或输入 bean,则必须在分页内发送三个值作为三个单独的参数。保持参数和 bean 字段名称相同以自动填充这些字段

于 2015-06-04T20:20:44.770 回答