SpringBoot全局捕获异常示例

//全局捕获异常对basePackages的包生效
@ControllerAdvice(basePackages = "com.wld.controller")
public class GlobalExpectionHandler(){
	
	//@ExceptionHandler(RuntimeException.class)仅仅捕获RuntimeException异常类型
	@ExceptionHandler(RuntimeException.class)
	//@ResponseBody 返回json格式
	//ModeAndView 返回页面
	@ResponseBody
	public Map<String,Object> errorResult(){
		Map<String,Object> resultMap = new HashMap<String,Object>();
		resultMap.put("errorCode", "500");
		resultMap.put("errorMessage", "system Error")
		return resultMap;
	}	
}
posted @ 2019-03-20 23:35  嗯哼~  阅读(294)  评论(0编辑  收藏  举报