你的位置:首页 > 信息动态 > 新闻中心
信息动态
联系我们

3.全局异常处理

2022/8/27 20:48:26

package com.serlyf.server.exception;

import java.sql.SQLException;
import java.sql.SQLIntegrityConstraintViolationException;

import org.springframework.web.bind.annotation.RestControllerAdvice;

import com.serlyf.server.pojo.Result;

/**

  • 全局异常
  • @author zhanglishen
    */

@RestControllerAdvice
public class GlobalException {

public Result mySQLException(SQLException e){
    if (e instanceof SQLIntegrityConstraintViolationException){
        return Result.ERROR("该数据有关数据,操作失败!");
    }
    return Result.ERROR("数据库异常,操作失败!");
}

}