0

I have a URL mapping on my Spring REST controller that expects the URL to have three optional request parmeters. I have used @RequestParam annotation to define three optional parameters in the method that I defined below. The URL works fine when I use a browser to hit the same.

The problem is when I try to hit the same url with my AngularJS service. I have worked with PathVariables in the past but am not sure how to pass these RequestParam variables into the URL.

Angular Service:

$resource(configuration.get('wsUrlPrefix') + 'abc/xyz/:page/:size/:sortData', {}, serviceConfig)

The URL turns out to be something like this:

http://localhost:8080/abc/xyz//10?sortdata=%7B%22orderType%22:null,%22oEDistrictNbr%22:null,%22orderNumber%22:null,%22mainLine%22:null%7D

and the backend is not able to recognize it.

1 Answer 1

1

This is because your sortdata parameter is an object, e.g. like this:

{ 
  orderType: null,
  eEDistrictNbr:null
  ..
}

So when this is encoded it will become like in your question (escaped chars, etc)

One way to fix it is to make sure your parameters are always strings or numbers, by deconstructing your object into simple primitives, e.g.

$resource(configuration.get('wsUrlPrefix') + 'abc/xyz/:page/:size/:sortDataOrderType/:sortDataEDistricNr/...', {}, serviceConfig)
Sign up to request clarification or add additional context in comments.

1 Comment

Yes thanks. But in order to pass url parameters I used the ? symbol at the end of the param name. It worked thanks.

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.