SpringBoot全局捕获异常示例

SpringBoot全局捕获异常示例

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

你可能感兴趣的:(SpringBoot全局捕获异常示例)