0 votes
302 views
asked in JAVA by (8.2k points)
Hi

  What is @pathVariable and how to use it? possible provide the sample code too?

2 Answers

0 votes
answered by

@PathVariable:-
     A path variable in the URI could be injected as a parameter using the @PathVariable annotation.
For example:
@RequestMapping(method=RequestMethod.GET, value="/emp/{id}")
public ModelAndView getEmployee(@PathVariable String id) { … }

0 votes
answered by

Review a Spring MVC @RequestMapping and @PathVariable example.

@RequestMapping("/site")
public class SiteController {
    @RequestMapping(value = "/{q}", method = RequestMethod.GET)
    public ModelAndView display(@PathVariable("q") String q) {
        logger.debug("Site : q : {}", q);
        return getModelAndView(q, "site");
    }
}

Categories

...