@ControllerAdvice(annotations = {RestController.class})
@ResponseBody
@Slf4j
public class GlobalExceptionHandler {
@ExceptionHandler(SQLIntegrityConstraintViolationException.class)
private R<String> exceptionhander(SQLIntegrityConstraintViolationException ex){
// log.info(ex.getMessage());
if(ex.getMessage().contains("Duplicate entry")){
String s = "已存在";
String[] split = ex.getMessage().split(" ");
String mag = split[2] + s;
return R.error(mag);
}
return R.error("操作失败!");
}
}
外卖项目——设置一个全局的捕获异常类
最新推荐文章于 2024-07-21 12:12:15 发布