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

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

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

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

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

@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; }

補(bǔ)充:springboot的PathVariable接收參數(shù)值帶點(diǎn)號(hào)問(wèn)題

問(wèn)題

@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; }

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教。

標(biāo)簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 会昌县| 颍上县| 阜阳市| 汶上县| 平泉县| 浮山县| 海安县| 镇沅| 晋中市| 伊金霍洛旗| 武平县| 顺义区| 曲阜市| 乐清市| 化隆| 桦南县| 连云港市| 泽库县| 蛟河市| 渝中区| 辽宁省| 隆回县| 合作市| 达拉特旗| 滕州市| 漳浦县| 临清市| 盐源县| 应城市| 浦县| 奉新县| 开化县| 西和县| 炎陵县| 周宁县| 西乌| 永城市| 北川| 铜鼓县| 呼图壁县| 鹤山市|