@PathVariable in SpringBoot with slashes in URL

Basing on P.J.Meisch’s answer I have come to the simple solution for my case. Also it allows to take into account several slashes in the URL param. It doesn’t allow to work with backslashes as in the previous answer too.

@RequestMapping(value = "/modules/**", method = RequestMethod.GET)
@ResponseBody
public String moduleStrings(HttpServletRequest request) {

    String requestURL = request.getRequestURL().toString();

    String moduleName = requestURL.split("/modules/")[1];

    return "module name is: " + moduleName;

}

Leave a Comment