03.全局异常处理

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("数据库异常,操作失败!");
}

}

posted @ 2022-08-27 20:45  NIANER2011  阅读(36)  评论(0编辑  收藏  举报