From 6840faa9d8bbe2459b40f5ced96fcbcb1f42154e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98=E6=AF=9B=E6=96=87=E6=98=A5=E2=80=99?= <739897791@qq.com> Date: Wed, 19 Jun 2024 13:44:53 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E6=96=B0=E5=A2=9E=E5=AD=97=E7=AC=A6?= =?UTF-8?q?=E4=B8=B2=E5=A4=84=E7=90=86=E5=B7=A5=E5=85=B7=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tiesheng/core/util/CharacterUtils.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 springboot-web/src/main/java/com/tiesheng/core/util/CharacterUtils.java diff --git a/springboot-web/src/main/java/com/tiesheng/core/util/CharacterUtils.java b/springboot-web/src/main/java/com/tiesheng/core/util/CharacterUtils.java new file mode 100644 index 0000000..39ea774 --- /dev/null +++ b/springboot-web/src/main/java/com/tiesheng/core/util/CharacterUtils.java @@ -0,0 +1,44 @@ +package com.tiesheng.core.util; + + +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; + +import java.util.Map; + +public class CharacterUtils { + + + /** + * 移除特殊字符 + * + * @param o 类 + */ + private void removeSymbol(Object o) { + removeSymbol(o, "\n|\r|\t| "); + } + + /** + * 移除特殊字符 + * + * @param o 类 + * @param searchStr 规则 + */ + private void removeSymbol(Object o, String searchStr) { + JSONObject object = JSONUtil.parseObj(o, false); + for (Map.Entry entry : object) { + if (ObjectUtil.isEmpty(entry.getValue()) || StrUtil.equals("null", String.valueOf(entry.getValue()))) { + entry.setValue(""); + continue; + } + if (StrUtil.isNotEmpty(entry.getKey())) { + entry.setValue(StrUtil.trim(StrUtil.replace(entry.getValue().toString(), searchStr, ""))); + } + } + BeanUtil.copyProperties(object, o); + } + +}