spring mvc-獲取 @resposeBody
阿新 • • 發佈:2018-06-26
方式 clas 狀態 cut nts logger esc str G1
import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.core.MethodParameter; import org.springframework.http.MediaType; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.server.ServerHttpRequest; import org.springframework.http.server.ServerHttpResponse;import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice; /** * 日誌跟蹤記錄接口參數及返回狀態 * * @fileName CatResponseBodyAdvice.java * @Description * @author light-zhang * @date 2018年6月26日下午2:55:55 *@version 1.0.0 */ @Controller @ControllerAdvice public class CatResponseBodyAdvice implements ResponseBodyAdvice<ReturnMsg<?>> { private static final Logger logger = LoggerFactory.getLogger(CatResponseBodyAdvice.class); @Override public ReturnMsg<?> beforeBodyWrite(ReturnMsg<?> arg0, MethodParameter arg1, MediaType arg2, Class<? extends HttpMessageConverter<?>> arg3, ServerHttpRequest arg4, ServerHttpResponse arg5) { logger.info("方式:{},請求地址信息:{}", arg4.getMethod().name(), arg4.getURI().toString()); logger.info("請求函數名稱:{},請求媒體類型信息:{}", arg1.getExecutable().getName(), arg2.toString()); logger.info("響應參數信息:{}", arg0); return arg0; } @Override public boolean supports(MethodParameter arg0, Class<? extends HttpMessageConverter<?>> arg1) { return true; } }
spring mvc-獲取 @resposeBody