DEV Community

Cheav Sovannarith
Cheav Sovannarith

Posted on • Originally published at Medium on

Using Map<String, String> with @PathVariable

Is that map populated with all path variable names and values?

Photo by David Martin on Unsplash

@PathVariable is a Spring annotation which indicates that a method parameter should be bound to a URI template variable. If the method parameter is Map then the map is populated with all path variable names and values.

It has the following optional elements:

  • name — name of the path variable to bind to
  • required — tells whether the path variable is required
  • value — alias for name
@GetMapping(value = "/book/{author}/{title}")
public void process3(@PathVariable Map<String, String> vals) {

   logger.info("{}: {}", vals.get("author"), vals.get("title"));

}
Enter fullscreen mode Exit fullscreen mode

Doc : http://zetcode.com/spring/pathvariable/


Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs