Prechádzať zdrojové kódy

添加唯一索引异常捕获

ControlDream 2 rokov pred
rodič
commit
b0806c16df

+ 10 - 0
ruoyi-framework/src/main/java/com/ruoyi/framework/web/exception/GlobalExceptionHandler.java

@@ -7,6 +7,7 @@ import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.common.utils.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.dao.DuplicateKeyException;
 import org.springframework.security.access.AccessDeniedException;
 import org.springframework.validation.BindException;
 import org.springframework.web.HttpRequestMethodNotSupportedException;
@@ -36,6 +37,15 @@ public class GlobalExceptionHandler {
     }
 
     /**
+     * 权限校验异常
+     */
+    @ExceptionHandler(DuplicateKeyException.class)
+    public AjaxResult handleDuplicateKeyException(DuplicateKeyException e) {
+        log.error("唯一索引重复", e);
+        return AjaxResult.error(HttpStatus.ERROR, "系统繁忙,请稍后重试!");
+    }
+
+    /**
      * 请求方式不支持
      */
     @ExceptionHandler(HttpRequestMethodNotSupportedException.class)

+ 2 - 2
ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml

@@ -125,7 +125,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <if test="orderNum != null">order_num,</if>
         <if test="leaderId != null and leaderId != ''">leader_id,</if>
         <if test="directorId != null and directorId != ''">director_id,</if>
-        <if test="type != null and type != ''">type,</if>
+        <if test="type != null">type,</if>
         <if test="phone != null and phone != ''">phone,</if>
         <if test="email != null and email != ''">email,</if>
         <if test="status != null">status,</if>
@@ -140,7 +140,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <if test="orderNum != null">#{orderNum},</if>
         <if test="leaderId != null and leaderId != ''">#{leaderId},</if>
         <if test="directorId != null and directorId != ''">#{directorId},</if>
-        <if test="type != null and type != ''">#{type},</if>
+        <if test="type != null">#{type},</if>
         <if test="phone != null and phone != ''">#{phone},</if>
         <if test="email != null and email != ''">#{email},</if>
         <if test="status != null">#{status},</if>