如何在 spring-mvc 中创建具有未知数量的 @PathVariables 的 url 模式?
How to create url pattern with unknown number of @PathVariables in spring-mvc?
我正在寻找符合以下条件的单个 url 模式:
www.example.com/asset/{pathvariable10}/{pathvariable11}/{pathvariable12}
www.example.com/asset/{pathvariable20}/{pathvariable21}/{pathvariable22}
www.example.com/asset/{pathvariable30}/{pathvariable31}/{pathvariable32}/{pathvariable33}/{pathvariable34}
.
.
.'
www.example.com/asset/{pathvariable80}/{pathvariable81}/{pathvariable82}
www.example.com/asset/{pathvariable90}/{pathvariable91}/{pathvariable92}
www.example.com/asset/{pathvariable100}/{pathvariable101}/{pathvariable102}/{pathvariable103}/{pathvariable104}
这个问题的可能答案之一是使用:
`@RequestMapping(value = "/asset/**", method = RequestMethod.GET`)
这将允许任意数量的@PathVariables.However获取我们可以使用的变量的实际值:
String requestedUri = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
。在字符串中搜索我们想要的任何内容,requestedUri
。例如:
if (requestedUri.toLowerCase().contains("new")){
registerNewAsset();
}else if (requestedUri.toLowerCase().contains("edit")){
editAsset(asset_id);
}else if (requestedUri.toLowerCase().contains("delete")){
deleteAsset(asset_id);
}else if (requestedUri.toLowerCase().contains("list")){
listAssets()
}
剩下的就是历史了。
我正在寻找符合以下条件的单个 url 模式:
www.example.com/asset/{pathvariable10}/{pathvariable11}/{pathvariable12} www.example.com/asset/{pathvariable20}/{pathvariable21}/{pathvariable22} www.example.com/asset/{pathvariable30}/{pathvariable31}/{pathvariable32}/{pathvariable33}/{pathvariable34}
.
.
.'
www.example.com/asset/{pathvariable80}/{pathvariable81}/{pathvariable82} www.example.com/asset/{pathvariable90}/{pathvariable91}/{pathvariable92} www.example.com/asset/{pathvariable100}/{pathvariable101}/{pathvariable102}/{pathvariable103}/{pathvariable104}
这个问题的可能答案之一是使用:
`@RequestMapping(value = "/asset/**", method = RequestMethod.GET`)
这将允许任意数量的@PathVariables.However获取我们可以使用的变量的实际值:
String requestedUri = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
。在字符串中搜索我们想要的任何内容,requestedUri
。例如:
if (requestedUri.toLowerCase().contains("new")){
registerNewAsset();
}else if (requestedUri.toLowerCase().contains("edit")){
editAsset(asset_id);
}else if (requestedUri.toLowerCase().contains("delete")){
deleteAsset(asset_id);
}else if (requestedUri.toLowerCase().contains("list")){
listAssets()
}
剩下的就是历史了。