Java 从泽西那里得到身份证
我正在尝试向Java Jersey后端发送ID。 问题是控制台给了我0而不是1,这意味着该方法没有收到id 这是我的angularJs$http,我在其中发送一个json对象id:Java 从泽西那里得到身份证,java,angularjs,jersey,Java,Angularjs,Jersey,我正在尝试向Java Jersey后端发送ID。 问题是控制台给了我0而不是1,这意味着该方法没有收到id 这是我的angularJs$http,我在其中发送一个json对象id: $http({ url: '/mav8/rest/users/getUserById', dataType: 'json', method: 'POST', data: '{'id':1}', headers: { "Content-Type": "appl
$http({
url: '/mav8/rest/users/getUserById',
dataType: 'json',
method: 'POST',
data: '{'id':1}',
headers: {
"Content-Type": "application/json"
}
}).success(function(response){
$scope.response = response;
}).error(function(error){
$scope.error = error;
});
我的userRestService中有这个方法,它可以工作,但不接收或读取id值。println正在我的后端控制台中键入0
@POST
@Path("getUserById")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public User getUserByIdInJSON(int id) {
UserService userService = new UserService();
System.out.println(id);
return userService.getUserById();
}
我的其余代码运行良好,我可以得到一个用户列表等
如果您有任何想法,非常感谢。试试这个
$http().get('/mav8/rest/users/getUserById?id=1').success(function(response){
$scope.response = response;
}).error(function(error){
$scope.error = error;
});
@GET
@Path("getUserById")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public User getUserByIdInJSON(@QueryParam("id") int id) {
UserService userService = new UserService();
System.out.println(id);
return userService.getUserById();
}
或
可能会有帮助。非常感谢你,我明天会尽量让你知道的!第二个很好用,非常感谢,我正在试着制造一个积垢,而实际上这一点都不容易。
$http().get('/mav8/rest/users/getUserById/1').success(function(response){
$scope.response = response;
}).error(function(error){
$scope.error = error;
});
@GET
@Path("getUserById/{id}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public User getUserByIdInJSON(@PathParam("id") int id) {
UserService userService = new UserService();
System.out.println(id);
return userService.getUserById();
}