spring boot @PathVariable傳遞帶反斜杠參數(shù) / 的處理
我就廢話不多說(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ò)誤或未考慮完全的地方,望不吝賜教。
相關(guān)文章:
1. jsp+servlet簡(jiǎn)單實(shí)現(xiàn)上傳文件功能(保存目錄改進(jìn))2. .Net反向代理組件Yarp用法詳解3. 解決request.getParameter取值后的if判斷為NULL的問(wèn)題4. .NET Framework各版本(.NET2.0 3.0 3.5 4.0)區(qū)別5. 詳解JSP 內(nèi)置對(duì)象request常見(jiàn)用法6. JSP中param動(dòng)作的實(shí)例詳解7. ASP.NET MVC實(shí)現(xiàn)下拉框多選8. ASP.NET MVC增加一條記錄同時(shí)添加N條集合屬性所對(duì)應(yīng)的個(gè)體9. .NET中的MassTransit分布式應(yīng)用框架詳解10. ASP.NET MVC實(shí)現(xiàn)本地化和全球化
