[英]How to access @PathVariable in a Spring MVC exception handler?
做這樣的事情是否有效:
@RequestMapping(method = RequestMethod.POST)
public @ResponseBody Post doSomething(@PathVariable postId) {
}
@ExceptionHandler(Exception.class)
private ModelAndView handleException(Exception ex, @PathVariable postId) {
}
當我在其方法簽名中添加@PathVariable
時,Spring似乎忽略了我的異常處理程序。
也許是這樣嗎? (控制器中的方法)
private Optional<String> getPathVariable(String paramName) {
return Optional.ofNullable((Map<String, String>) request.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE))
.filter(map -> map.containsKey(paramName))
.map(map -> map.get(paramName));
}
海事組織,無論如何,這種信息都應包含在例外本身之內。
我不知道異常處理程序會獲取路徑變量。
@ExceptionHandler方法中確實不支持@PathVariable。 但是,在Spring 3.1中,您應該能夠使用PathVariableMethodArgumentResolver配置ExceptionHandlerExceptionResolver,這應該可以使其正常工作。 隨意在JIRA中打開票證,好像我們可以添加一些東西。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.