I am not able to find a way to use angularjs's $http.get to pass filter params.
Url is:
http://localhost:8080/template/users/query;username=abcd;firstName=ding...
RestController is:
@RequestMapping(value={"/users/{query}"}, method=RequestMethod.GET)
public ResponseEntity<List<User>> queryUsers(@MatrixVariable(pathVar="query") Map<String, List<String>> filters) {
....
}
When I use the above Url directly in the browser it is working fine. However when I try to call the same using Angularjs's $http.get it is not working.
Angularjs code:
this.searchUser = function() {
var queryStr = '';
for (var key in userObj.search) {
if (userObj.search[key]) {
queryStr += ";" + key + "=" + userObj.search[key];
}
}
console.log('Url ', 'users/query' + queryStr);
if (queryStr === "") {
alert("No filters specified");
return false;
}
$http.get('users/query', angular.toJson(userObj.search)).then(function successCallback(response) {
if (response.data.errorCode) {
console.log(response);
alert(response.data.message);
} else {
console.log('Successfully queried for users ', response.data);
userObj.users = response.data;
}
}, function errorCallback(response) {
console.log('Error ', response);
alert(response.statusText);
});
};
When I call this method: I get the error as
errorCode: 400
message: "Failed to convert value of type [java.lang.String] to required type [long]; nested exception is java.lang.NumberFormatException: For input string: "query""
Even I tried to pass the query string as it is mentioned in the above URL, but still the same error. I am sure it is not even entering inside the RestController method.
How to solve this?