update 在全局异常处理器中引入 主键或UNIQUE索引 数据重复异常

2.X
疯狂的狮子Li 3 years ago
parent 08da8911f7
commit 6cf2f5794c

@ -10,6 +10,7 @@ import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.exception.DemoModeException;
import com.ruoyi.common.core.exception.ServiceException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.validation.BindException;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.MethodArgumentNotValidException;
@ -78,6 +79,16 @@ public class GlobalExceptionHandler {
return R.fail(e.getMessage());
}
/**
* UNIQUE
*/
@ExceptionHandler(DuplicateKeyException.class)
public R<Void> handleDuplicateKeyException(DuplicateKeyException e, HttpServletRequest request) {
String requestURI = request.getRequestURI();
log.error("请求地址'{}',数据库中已存在记录'{}'", requestURI, e.getMessage());
return R.fail("数据库中已存在该记录,请联系管理员确认");
}
/**
*
*/

Loading…
Cancel
Save