上网找过很多文章都说实现 HandlerMethodReturnValueHandler 接口 本人试过 不行,查看源码才知道,需要实现AsyncHandlerMethodReturnValueHandler
废话少说:
1、实现AsyncHandlerMethodReturnValueHandler 接口
public class ArgsHandlerMethodReturnValueHandler implements AsyncHandlerMethodReturnValueHandler {
@Override
public boolean supportsReturnType(MethodParameter returnType) {
Class<?> type = returnType.getParameterType();
return true;
}
@Override
public void handleReturnValue(Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer,
NativeWebRequest webRequest) throws Exception {
// TODO Auto-generated method stub
}
@Override
public boolean isAsyncReturnValue(Object returnValue, MethodParameter returnType) {
// TODO Auto-generated method stub
if(returnValue instanceof ReturnData ) {
ReturnData rd=(ReturnData) returnValue;
LogPutUtils.putData("ret", rd.getRet());
} else if(returnValue instanceof ReturnListData){
ReturnListData rd=(ReturnListData) returnValue;
LogPutUtils.putData("ret", rd.getRet());
} else if(returnValue instanceof Map) {
Map rd=( Map) returnValue;
LogPutUtils.putData("ret", rd.get("ret"));
}
return false;
}
}
isAsyncReturnValue 中 的 returnValue就是 Controller的返回值
2、在springmvc配置文件中定义:
<mvc:annotation-driven >
<mvc:return-value-handlers>
<bean class="cn.bevol.web.interceptor.ArgsHandlerMethodReturnValueHandler"></bean>
</mvc:return-value-handlers>
</mvc:annotation-driven>