From 4b067b4db5c1f2a068d6e27cc138118810785e2d Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期三, 07 五月 2025 10:47:13 +0800
Subject: [PATCH] 1、创建命令生成器模块,实现部分命令数据生成,还需继续实现其他命令; 2、完善代码。
---
pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/fastjson/FastJsonConfig.java | 78 +++++++++++++++++++++++++++++++++++++++
1 files changed, 78 insertions(+), 0 deletions(-)
diff --git a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/fastjson/FastJsonConfig.java b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/fastjson/FastJsonConfig.java
new file mode 100644
index 0000000..e57c5dc
--- /dev/null
+++ b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/fastjson/FastJsonConfig.java
@@ -0,0 +1,78 @@
+package com.dy.common.fastjson;
+
+
+import com.alibaba.fastjson2.JSONWriter;
+import com.alibaba.fastjson2.support.spring6.http.converter.FastJsonHttpMessageConverter;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.http.MediaType;
+import org.springframework.http.converter.HttpMessageConverter;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 蹇呴』瀹炵幇WebMvcConfigurer鍚﹀垯涓嶅惎浣滅敤锛屽嵆Controller杞琷son鏃朵笉鐢╢astjson
+ */
+@Configuration
+public class FastJsonConfig implements WebMvcConfigurer {
+ /**
+ * 閰嶇疆fastjson杈撳嚭鏍煎紡
+ **/
+ @Override
+ public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
+ // 1. 閰嶇疆fastjson
+ com.alibaba.fastjson2.support.config.FastJsonConfig config = new com.alibaba.fastjson2.support.config.FastJsonConfig();
+
+ config.setDateFormat("yyyy-MM-dd HH:mm:ss");
+ config.setCharset(StandardCharsets.UTF_8);
+ config.setWriterFeatures(
+ //杈撳嚭map涓璿alue涓簄ull鐨勬暟鎹�
+ JSONWriter.Feature.WriteMapNullValue,
+ //杈撳嚭null鐨刡oolean 涓� false
+ JSONWriter.Feature.WriteNullBooleanAsFalse,
+ //鎶奓ong鍨嬭緭鍑轰负String锛屽湪pojo鐨勫睘鎬т腑涓�ц缃�
+ //JSONWriter.Feature.WriteLongAsString,
+ //杈撳嚭null鐨刲ist 涓� []
+ JSONWriter.Feature.WriteNullListAsEmpty,
+ //杈撳嚭null鐨刵umber 涓� 0
+ //JSONWriter.Feature.WriteNullNumberAsZero,
+ //杈撳嚭null瀛楃涓� 涓� ""
+ JSONWriter.Feature.WriteNullStringAsEmpty,
+ //瀵筸ap杩涜鎺掑簭
+ JSONWriter.Feature.MapSortField,
+ //json鏍煎紡鍖�
+ JSONWriter.Feature.PrettyFormat
+ );
+
+ // 2. 娣诲姞fastjson杞崲鍣�
+ FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();
+ converter.setDefaultCharset(StandardCharsets.UTF_8);
+
+ // 3. 娣诲姞鏀寔鐨勫獟浣撶被鍨�
+ List<MediaType> supportedMediaTypes = new ArrayList<>();
+ supportedMediaTypes.add(MediaType.APPLICATION_JSON);
+ supportedMediaTypes.add(MediaType.APPLICATION_ATOM_XML);
+ supportedMediaTypes.add(MediaType.APPLICATION_FORM_URLENCODED);
+ supportedMediaTypes.add(MediaType.APPLICATION_OCTET_STREAM);
+ supportedMediaTypes.add(MediaType.APPLICATION_PDF);
+ supportedMediaTypes.add(MediaType.APPLICATION_RSS_XML);
+ supportedMediaTypes.add(MediaType.APPLICATION_XHTML_XML);
+ supportedMediaTypes.add(MediaType.APPLICATION_XML);
+ supportedMediaTypes.add(MediaType.IMAGE_GIF);
+ supportedMediaTypes.add(MediaType.IMAGE_JPEG);
+ supportedMediaTypes.add(MediaType.IMAGE_PNG);
+ supportedMediaTypes.add(MediaType.TEXT_EVENT_STREAM);
+ supportedMediaTypes.add(MediaType.TEXT_HTML);
+ supportedMediaTypes.add(MediaType.TEXT_MARKDOWN);
+ supportedMediaTypes.add(MediaType.TEXT_PLAIN);
+ supportedMediaTypes.add(MediaType.TEXT_XML);
+
+ converter.setSupportedMediaTypes(supportedMediaTypes);
+
+ //4 灏哻onvert娣诲姞鍒癱onverters
+ converter.setFastJsonConfig(config);
+ converters.add(0,converter);
+ }
+}
--
Gitblit v1.8.0