spring boot @PathVariable传递带反斜杠参数 / 的处理

网友投稿 726 2023-02-10

spring boot @PathVariable传递带反斜杠参数 / 的处理

spring boot @PathVariable传递带反斜杠参数 / 的处理

我就废话不多说了,大家还是看完整的代码吧~

@RequestMAPPing(value = "/modules/{moduleBaseName}/**", method = RequestMethod.Ghttp://ET)

@ResponseBody

public String moduleStrings(@PathVariable String moduleBaseNhttp://ame, HttpServletRequest request) {

final String path =

request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE).toString();

final String bestMatchingPattern =

request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE).toString();

String arguments = new AntPathMatcher().extractPathWithinPattern(bestMatchingPattern, path);

String moduleName;

if (null != arguments && !arguments.isEmpty()) {

moduleName = moduleBaseName + '/' + arguments;

} else {

moduleName = moduleBaseName;

}

return "module name is: " + moduleName;

}

补充:springboot的PathVariable接收参数值带点号问题

问题

@RequestMapping(value = "/{version}",method = RequestMethod.GET)

public String demo(@PathVariable String version){

return version;

}

如果version是1.0.0,则返回1.0,这俨然不是我们所期望的。

解决

@RequestMapping(value = "/{version:.+}",method = RequestMethod.GET)

public String demo(@PathVariable String version){

return version;

}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:app运营模式违法吗(app运营模式和盈利模式)
下一篇:解决@PathVariable对于特殊字符截断的问题
相关文章

 发表评论

暂时没有评论,来抢沙发吧~