繁体   English   中英

Spring AngularJS获取请求

[英]Spring AngularJS get request

我正在尝试对我的用户列表进行分页。 尝试在请求中使用参数时出现错误“错误的请求”。 可能是什么问题?

UserController.java

@RequestMapping(value = "/user/{page}",params ={"size"}, method = RequestMethod.GET)
    public ResponseEntity<List<User>> getList(@PathVariable("page") int page, @RequestParam("size") int size) {    
        List usersList = userService.getList(page, size);    
        ResponseEntity<List<User>> respEntity = null;    
        if(usersList.isEmpty()){
            respEntity =new ResponseEntity<List<User>>(HttpStatus.NO_CONTENT);
            return respEntity;
        }    
        respEntity =new ResponseEntity<List<User>>(usersList, HttpStatus.OK);    
        return respEntity;    
    }

user_service.js

fetchAllUsers: function(page, size) {
                return $http.get('http://localhost:8080/user/' + page, size)
                        .then(
                                function(response){
                                    console.log(response.data);
                                    console.table(response.data);
                                    return response.data;
                                }, 
                                function(errResponse){
                                    console.error('Error while fetching users');
                                    return $q.reject(errResponse);
                                }
                        );
        },

$ http.get文档说:

get(url,[config]);

[...]

config(可选)对象可选配置对象

您将传递大小作为第二个参数,而不是配置对象。 正确的代码是

$http.get('http://localhost:8080/user/' + page, {
    params: {
        size: size
    }
})...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM