From 9b4433fddf5b401edb0aace8a404ac733b122702 Mon Sep 17 00:00:00 2001
From: 田源 <tianyuan@vci-tech.com>
Date: 星期四, 03 四月 2025 14:35:02 +0800
Subject: [PATCH] 添加非密字段显示

---
 Source/BladeX-Tool/blade-core-tool/src/main/java/org/springblade/core/tool/utils/ConvertUtil.java |   81 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 81 insertions(+), 0 deletions(-)

diff --git a/Source/BladeX-Tool/blade-core-tool/src/main/java/org/springblade/core/tool/utils/ConvertUtil.java b/Source/BladeX-Tool/blade-core-tool/src/main/java/org/springblade/core/tool/utils/ConvertUtil.java
new file mode 100644
index 0000000..2772560
--- /dev/null
+++ b/Source/BladeX-Tool/blade-core-tool/src/main/java/org/springblade/core/tool/utils/ConvertUtil.java
@@ -0,0 +1,81 @@
+package org.springblade.core.tool.utils;
+
+import org.springblade.core.tool.convert.BladeConversionService;
+import org.springframework.core.convert.TypeDescriptor;
+import org.springframework.core.convert.support.GenericConversionService;
+import org.springframework.lang.Nullable;
+
+/**
+ * 鍩轰簬 spring ConversionService 绫诲瀷杞崲
+ *
+ * @author L.cm
+ */
+@SuppressWarnings("unchecked")
+public class ConvertUtil {
+
+	/**
+	 * Convenience operation for converting a source object to the specified targetType.
+	 * {@link TypeDescriptor#forObject(Object)}.
+	 * @param source the source object
+	 * @param targetType the target type
+	 * @param <T> 娉涘瀷鏍囪
+	 * @return the converted value
+	 * @throws IllegalArgumentException if targetType is {@code null},
+	 * or sourceType is {@code null} but source is not {@code null}
+	 */
+	@Nullable
+	public static <T> T convert(@Nullable Object source, Class<T> targetType) {
+		if (source == null) {
+			return null;
+		}
+		if (ClassUtil.isAssignableValue(targetType, source)) {
+			return (T) source;
+		}
+		GenericConversionService conversionService = BladeConversionService.getInstance();
+		return conversionService.convert(source, targetType);
+	}
+
+	/**
+	 * Convenience operation for converting a source object to the specified targetType,
+	 * where the target type is a descriptor that provides additional conversion context.
+	 * {@link TypeDescriptor#forObject(Object)}.
+	 * @param source the source object
+	 * @param sourceType the source type
+	 * @param targetType the target type
+	 * @param <T> 娉涘瀷鏍囪
+	 * @return the converted value
+	 * @throws IllegalArgumentException if targetType is {@code null},
+	 * or sourceType is {@code null} but source is not {@code null}
+	 */
+	@Nullable
+	public static <T> T convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
+		if (source == null) {
+			return null;
+		}
+		GenericConversionService conversionService = BladeConversionService.getInstance();
+		return (T) conversionService.convert(source, sourceType, targetType);
+	}
+
+	/**
+	 * Convenience operation for converting a source object to the specified targetType,
+	 * where the target type is a descriptor that provides additional conversion context.
+	 * Simply delegates to {@link #convert(Object, TypeDescriptor, TypeDescriptor)} and
+	 * encapsulates the construction of the source type descriptor using
+	 * {@link TypeDescriptor#forObject(Object)}.
+	 * @param source the source object
+	 * @param targetType the target type
+	 * @param <T> 娉涘瀷鏍囪
+	 * @return the converted value
+	 * @throws IllegalArgumentException if targetType is {@code null},
+	 * or sourceType is {@code null} but source is not {@code null}
+	 */
+	@Nullable
+	public static <T> T convert(@Nullable Object source, TypeDescriptor targetType) {
+		if (source == null) {
+			return null;
+		}
+		GenericConversionService conversionService = BladeConversionService.getInstance();
+		return (T) conversionService.convert(source, targetType);
+	}
+
+}

--
Gitblit v1.9.3