StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw, true));
String msg = sw.toString();
logger.error("批量等级更新失败 e:" + msg);
这样可以将详细的日志记录下来,方便查找问题;
也可以使用apache.commons.lang.exception下面的工具类:ExceptionUtils工具类
ExceptionUtils.getStackTrace(e);
if (exception instanceof BindingResult) { return onBindError((BindingResult) exception); } else if (exception instanceof MethodArgumentNotValidException) { MethodArgumentNotValidException validException = (MethodArgumentNotValidException) exception; return onBindError(validException.getBindingResult()); } else if (exception instanceof MethodArgumentTypeMismatchException) { MethodArgumentTypeMismatchException mismatchException = (MethodArgumentTypeMismatchException) exception; String error = mismatchException.getName() + " should be of type " + mismatchException.getRequiredType().getName(); log.error(error, mismatchException); return Result.error(ResultCode.PARAMETER_ERROR); } else if (exception instanceof IllegalArgumentException) { IllegalArgumentException illegalArgumentException = (IllegalArgumentException) exception; String error = illegalArgumentException.getMessage(); log.error(error); return Result.error(ResultCode.PARAMETER_ERROR); } else if (exception instanceof SpotException) { log.error("ex", exception); SpotException spotException = (SpotException) exception; return Result.error(spotException.getRetCode()); }else if (exception instanceof HttpRequestMethodNotSupportedException){ log.error("ex", exception); return Result.error(ResultCode.UNKNOWN_EXCEPTION.getCode(), "request method error"); }