Gábor DANI
Gábor DANI

Reputation: 2135

POST @RequestParam Map<String, String> in Spring MVC returns empty map

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?

Upvotes: 0

Views: 2029

Answers (1)

Mahesh
Mahesh

Reputation: 110

@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

Upvotes: 1

Related Questions