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("数据库异常,操作失败!");
}
}
标签:SQLIntegrityConstraintViolationException,处理,Result,ERROR,import,全局,异常 From: https://www.cnblogs.com/NIAN2011/p/16631437.html