spring-boot统一处理返回给前台的数据格式(避免返回异常堆栈信息,干扰用户体验)

引用块内容

/**
 * spring boot 捕获异常-----捕获全局异常信息,统一返回给前台的数据格式
 * Created  by  yangchen on 2018/2/7
 */

@ControllerAdvice
public class ExceptionHandler {
    @org.springframework.web.bind.annotation.ExceptionHandler(value = Exception.class)
    @ResponseBody
    public  Object handler(Exception e){
        return ResultUtils.build(500,e.getMessage());
    }

}

你可能感兴趣的:(spring-boot统一处理返回给前台的数据格式(避免返回异常堆栈信息,干扰用户体验))