Search code examples
javaspringspring-restcontrollerrequest-mapping

@PathVariable Map syntax for url?


I have a controller which looks like

@RequestMapping(value = "/start/{params}", method = GET, produces = { APPLICATION_JSON_VALUE, APPLICATION_XML_VALUE })
String doStart(@PathVariable("params") Map<String,String> startParams)

How do i send the startParams from the url?

All my tries ends up with:

IllegalStateException: Cannot convert value of type [java.lang.String] to required type [java.util.Map]: no matching editors or conversion strategy found

Also it is not possible to send empty like

theurl/start/

it gives

dec 18, 2015 10:56:07 FM org.springframework.web.servlet.DispatcherServlet noHandlerFound WARNING: No mapping found for HTTP request with URI

Is it somehow possible to send no params, or do i need a separate method for that?:


Solution

  • You have to use @MatrixVariable instead of @PathVariable.

    have a look at this example Spring Matrix variable usage