1

I'm using the default JEE7 REST application on Netbeans. The REST method that I'm trying to call is:

@GET
@Path("{id}")
@Produces({"application/xml", "application/json"})
public Customer find(@PathParam("id") Integer id) {
    return super.find(id);
}

I can successfully get a list of all customers. However, when I get the customer ID on the client side with angular, it generates this URL:

http://localhost:8080/mavenproject2/customers?0=1 

(when I passed the ID of 1) The addition of "?" and the index added "0=" makes the call fail.

http://localhost:8080/mavenproject2/customers/1 works

My service looks like this:

   customerServices.factory('customerById', function ($resource) {
    return $resource('http://localhost:8080/mavenproject2/customers/:id', {id: "@id"}, {
        query: {method: 'GET', isArray: true}
    });
})

and my controller looks like this:

.controller('customerDetailsController', function ($scope, $routeParams, customerById) {
    $scope.customer = customerById.query($routeParams.customerId);

});

Assistance will be greatly appreciated.

2 Answers 2

2

You should pass the argument as object, having the field(s) specified with the @. For your case:

$scope.customer = customerById.query({ id: $routeParams.customerId });
Sign up to request clarification or add additional context in comments.

Comments

2

You could try something like this in your controller:

$scope.fetchData = function() {
    $http({
        method : 'GET',
        url : 'http://localhost:8080/mavenproject2/customers/',
        params : {id : theIdFromYourCode}
    }).success(function(data) {
        // do something
    }).error(function(data, status) {
        // do something if error
    });
}; 

Note that you will have to include the $http module.

1 Comment

Thank you for your reply. I tried to stay away from $http as I knew that angular would be able to talk to Java (the angular api just had to work ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.