springboot学习笔记(6)全局捕获异常

GlobalExceptionHandler

import java.util.HashMap;
import java.util.Map;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

//全局捕获异常
@ControllerAdvice
public class GlobalExceptionHandler {

	@ExceptionHandler(RuntimeException.class)
	@ResponseBody
	public Map<String,Object> resultError(){
		Map<String,Object> result = new HashMap<String,Object>();
		result.put("errorCode", "500");
		result.put("errorMsg", "系统错误..");
		return result;
	}
}
aop机制 :异常通知

猜你喜欢

转载自blog.csdn.net/huermiss/article/details/80259255