久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

spring boot @PathVariable傳遞帶反斜杠參數 / 的處理

瀏覽:4日期:2023-07-22 10:44:43

我就廢話不多說了,大家還是看完整的代碼吧~

@RequestMapping(value = '/modules/{moduleBaseName}/**', method = RequestMethod.GET) @ResponseBody public String moduleStrings(@PathVariable String moduleBaseName, 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; }

以上為個人經驗,希望能給大家一個參考,也希望大家多多支持好吧啦網。如有錯誤或未考慮完全的地方,望不吝賜教。

標簽: Spring
相關文章:
主站蜘蛛池模板: 五指山市| 山阳县| 福安市| 丰城市| 南丰县| 泸定县| 富川| 吉木萨尔县| 铜山县| 黄陵县| 黄大仙区| 邛崃市| 香河县| 赤壁市| 高邑县| 淮阳县| 元谋县| 巴彦淖尔市| 名山县| 尼勒克县| 东辽县| 唐河县| 三亚市| 惠州市| 从江县| 麦盖提县| 彩票| 和硕县| 镇巴县| 蒙自县| 增城市| 师宗县| 桃园市| 双流县| 砀山县| 景泰县| 张掖市| 阜新市| 剑河县| 宁晋县| 花垣县|