spring boot @PathVariable傳遞帶反斜杠參數(shù) / 的處理
我就廢話不多說了,大家還是看完整的代碼吧~
@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接收參數(shù)值帶點號問題
問題@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; }
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持好吧啦網(wǎng)。如有錯誤或未考慮完全的地方,望不吝賜教。
相關(guān)文章:
1. jstl 字符串處理函數(shù)2. JSP動態(tài)網(wǎng)頁開發(fā)原理詳解3. XHTML 1.0:標記新的開端4. Vue中使用Echarts儀表盤展示實時數(shù)據(jù)的實現(xiàn)5. 深入理解JavaScript中的Base64編碼字符串6. java 字符串轉(zhuǎn)化為字符數(shù)組的3種實現(xiàn)案例7. JSP頁面的靜態(tài)包含和動態(tài)包含使用方法8. WAP建站W(wǎng)ML語言語法基礎(chǔ)教程第1/6頁9. 基于python實現(xiàn)判斷字符串是否數(shù)字算法10. PHP擴展之URL編碼、解碼及解析——URLs
