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. 如何用python開(kāi)發(fā)Zeroc Ice應(yīng)用2. ASP錯(cuò)誤捕獲的幾種常規(guī)處理方式3. python用pyecharts實(shí)現(xiàn)地圖數(shù)據(jù)可視化4. python基于opencv批量生成驗(yàn)證碼的示例5. python軟件測(cè)試Jmeter性能測(cè)試JDBC Request(結(jié)合數(shù)據(jù)庫(kù))的使用詳解6. npm下載慢或下載失敗問(wèn)題解決的三種方法7. ASP編碼必備的8條原則8. Python查找算法之折半查找算法的實(shí)現(xiàn)9. python numpy.power()數(shù)組元素求n次方案例10. 使用Spry輕松將XML數(shù)據(jù)顯示到HTML頁(yè)的方法
