0

I have the following method:

@Controller
public class InterfaceController extends MasterController
{
    @PostMapping(value = "/interface") 
    @ResponseBody
    public String incomingPost(@RequestParam Map<String, String> queryMap)
    {
        System.out.println("Map: " + new Gson().toJson(queryMap));
        return "Raw string to return.";
    }
}

When I make a POST request to /interface, I get a successful 200 response with the dummy string I want to return with but the Map is not populated with my parameters:

Map: {}

Why?

1
  • how r u calling this endpoint can u show the url Commented Jan 17, 2018 at 18:22

1 Answer 1

1

@RequestParam works if you pass all your params as part of url.

If you are passing the data in request body, then you must use

@RequestBody Map<String, Object> queryMap
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, this was the problem. I was posting in the body instead of x-www-form-urlencoded.

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.