MVC Interceptor获取Exception处理程序方法的内容类型

时间:2013-07-28 23:32:56

标签: spring-mvc

如果我在控制器中有如下方法:

@RequestMapping(value = "/mymapping",
        method = RequestMethod.POST,
        produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public final JsonResponse<?> myMethod() {

当方法抛出异常时,我想要一个MVC拦截器来捕获它并返回一个JSON错误。我只希望这适用于控制器中的produces = MediaType.APPLICATION_JSON_VALUE方法。

如何在我的afterCompletion HandlerInterceptor中执行此操作。如果我检查响应的contentType,则在发生异常时为null。

@Override
public void afterCompletion(HttpServletRequest request,
        HttpServletResponse response, Object handler, Exception ex)
        throws Exception {
    //TODO
}

0 个答案:

没有答案
相关问题