xucaiqin 2 лет назад
Родитель
Сommit
69fcd48fbc

+ 6 - 0
iot-framework/iot-common/src/main/java/com/middle/platform/common/exception/ResultCode.java

@@ -5,6 +5,12 @@ package com.middle.platform.common.exception;
  * @date 2023-12-04 09:58:55
  */
 public class ResultCode {
+    //成功
     public static final int SUCCESS = 200;
+    //业务异常、参数校验异常等
+    public static final int FAILED = 102;
+    //兜底异常状态码
     public static final int ERROR = 500;
+    //未登录
+    public static final int UN_AUTH = 501;
 }

+ 3 - 3
iot-framework/iot-starter-web/src/main/java/com/middle/platform/web/config/GlobalExceptionHandler.java

@@ -47,7 +47,7 @@ public class GlobalExceptionHandler {
     @ExceptionHandler(value = NotLoginException.class)
     public Result<?> notLogin(Throwable ex) {
         log.error("[NotLoginException]", ex);
-        return Result.failed(ResultCode.ERROR, Global.UN_AUTH);
+        return Result.failed(ResultCode.UN_AUTH, Global.UN_AUTH);
     }
 
     @ResponseBody
@@ -67,7 +67,7 @@ public class GlobalExceptionHandler {
         }
         String errMsg = sb.toString();
         log.error("参数校验异常:{}", errMsg);
-        return Result.failed(ResultCode.ERROR, errMsg);
+        return Result.failed(ResultCode.FAILED, errMsg);
     }
     @ResponseBody
     @ExceptionHandler(ConstraintViolationException.class)
@@ -84,7 +84,7 @@ public class GlobalExceptionHandler {
                 first = false;
             }
         }
-        return Result.failed(ResultCode.ERROR, sb.toString());
+        return Result.failed(ResultCode.FAILED, sb.toString());
     }
 
 }

+ 21 - 0
iot-framework/iot-starter-web/src/main/java/com/middle/platform/web/config/JacksonConfig.java

@@ -0,0 +1,21 @@
+package com.middle.platform.web.config;
+
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * @author xucaiqin
+ * @date 2024-01-23 15:52:08
+ */
+@Configuration
+public class JacksonConfig {
+    @Bean
+    public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() {
+        return builder -> {
+            // 把 Long 类型序列化为 String
+            builder.serializerByType(Long.class, ToStringSerializer.instance);
+        };
+    }
+}

+ 1 - 0
iot-framework/iot-starter-web/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports

@@ -1 +1,2 @@
 com.middle.platform.web.config.GlobalExceptionHandler
+com.middle.platform.web.config.JacksonConfig