我就廢話不多說了,大家還是看完整的代碼吧~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
@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接收參數值帶點號問題
問題
1
2
3
4
|
@RequestMapping (value = "/{version}" ,method = RequestMethod.GET) public String demo( @PathVariable String version){ return version; } |
如果version是1.0.0,則返回1.0,這儼然不是我們所期望的。
解決
1
2
3
4
|
@RequestMapping (value = "/{version:.+}" ,method = RequestMethod.GET) public String demo( @PathVariable String version){ return version; } |
以上為個人經驗,希望能給大家一個參考,也希望大家多多支持服務器之家。如有錯誤或未考慮完全的地方,望不吝賜教。
原文鏈接:http://cn.voidcc.com/question/p-hdnhwour-ve.html