0

I need to take two parameters in my spring controller.

http://mydomain.com/myapp/getDetails?Id=13&subId=431

I have controller which will return Json for this request.

@RequestMapping(value = "/getDetails", method = RequestMethod.GET,params = "id,subId", produces="application/json")
    @ResponseBody
    public MyBean getsubIds(@RequestParam String id, @RequestParam String subId) {
     return MyBean
  }

I am getting 400 for when i tried to invoke the URL. Any thoughts on this? I was able to get it with one parameter.

1
  • 2
    Could it be that you're passing "Id" in your URL yet you specify "id" in the controller? (note lowercase/uppercase first letter) Commented Sep 18, 2013 at 21:44

2 Answers 2

2

Try specifying which parameter in the query string should match the parameter in the method like so:

public MyBean getsubIds(@RequestParam("id") String id, @RequestParam("subId") String subId) {

If the code is being compiled without the parameter names, Spring can have trouble figuring out which is which.

Sign up to request clarification or add additional context in comments.

1 Comment

@Adam try removing the parama section of the @RequestMapping. I've never needed those before...
1

As for me it works (by calling: http://www.example.com/getDetails?id=10&subId=15):

@RequestMapping(value = "/getDetails", method = RequestMethod.GET, produces="application/json")
@ResponseBody
public MyBean getsubIds(@RequestParam("id") String id, @RequestParam("subId") String subId) {
    return new MyBean();
}

P.S. Assuming you have class MyBean.

Comments

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.