From aec00d9ba27c46b8480222f29caa3c548c119dd0 Mon Sep 17 00:00:00 2001 From: zhangdaiscott Date: Sun, 6 Dec 2020 17:46:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E4=B8=AD=E6=96=87=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=90=8D=E8=BD=AC=E4=B8=BA=E6=8B=BC=E9=9F=B3=E3=80=81?= =?UTF-8?q?Long=E7=B1=BB=E5=9E=8B=E7=B2=BE=E5=BA=A6=E4=B8=A2=E5=A4=B1?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20issues/I24KXI=E3=80=81=E8=BE=BE=E6=A2=A6?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E5=85=BC=E5=AE=B9=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jeecg-boot-base-core/pom.xml | 6 ++++ .../org/jeecg/common/util/CommonUtils.java | 28 ++++++++++++++++++- .../org/jeecg/config/WebMvcConfiguration.java | 24 ++++++++++++++++ jeecg-boot/pom.xml | 1 + 4 files changed, 58 insertions(+), 1 deletion(-) diff --git a/jeecg-boot/jeecg-boot-base/jeecg-boot-base-core/pom.xml b/jeecg-boot/jeecg-boot-base/jeecg-boot-base-core/pom.xml index 4dad2579..3508233e 100644 --- a/jeecg-boot/jeecg-boot-base/jeecg-boot-base-core/pom.xml +++ b/jeecg-boot/jeecg-boot-base/jeecg-boot-base-core/pom.xml @@ -76,6 +76,12 @@ ${commons.version} + + + com.belerweb + pinyin4j + ${pinyin4j.version} + org.springframework.boot diff --git a/jeecg-boot/jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/CommonUtils.java b/jeecg-boot/jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/CommonUtils.java index f8fb0878..12b9b601 100644 --- a/jeecg-boot/jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/CommonUtils.java +++ b/jeecg-boot/jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/CommonUtils.java @@ -1,5 +1,7 @@ package org.jeecg.common.util; +import cn.hutool.core.util.StrUtil; +import cn.hutool.extra.pinyin.PinyinUtil; import lombok.extern.slf4j.Slf4j; import org.jeecg.common.constant.CommonConstant; import org.jeecg.common.constant.DataBaseConstant; @@ -16,10 +18,15 @@ import java.io.InputStream; import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.SQLException; +import java.util.regex.Matcher; +import java.util.regex.Pattern; @Slf4j public class CommonUtils { + //中文正则 + private static Pattern ZHONGWEN_PATTERN = Pattern.compile("[\u4e00-\u9fa5]"); + public static String uploadOnlineImage(byte[] data,String basePath,String bizPath,String uploadType){ String dbPath = null; String fileName = "image" + Math.round(Math.random() * 100000000000L); @@ -68,9 +75,28 @@ public class CommonUtils { } //替换上传文件名字的特殊字符 fileName = fileName.replace("=","").replace(",","").replace("&","").replace("#", ""); + //替换上传文件名字中的中文 + if(ifContainChinese(fileName)){ + fileName= PinyinUtil.getPinyin(fileName, StrUtil.EMPTY); + } + //替换上传文件名字中的空格 + fileName=fileName.replaceAll("\\s",""); return fileName; } + // java 判断字符串里是否包含中文字符 + public static boolean ifContainChinese(String str) { + if(str.getBytes().length == str.length()){ + return false; + }else{ + Matcher m = ZHONGWEN_PATTERN.matcher(str); + if (m.find()) { + return true; + } + return false; + } + } + /** * 统一全局上传 * @Return: java.lang.String @@ -129,7 +155,7 @@ public class CommonUtils { String dbType = md.getDatabaseProductName().toLowerCase(); if(dbType.indexOf("mysql")>=0) { DB_TYPE = DataBaseConstant.DB_TYPE_MYSQL; - }else if(dbType.indexOf("oracle")>=0) { + }else if(dbType.indexOf("oracle")>=0 ||dbType.indexOf("dm")>=0) { DB_TYPE = DataBaseConstant.DB_TYPE_ORACLE; }else if(dbType.indexOf("sqlserver")>=0||dbType.indexOf("sql server")>=0) { DB_TYPE = DataBaseConstant.DB_TYPE_SQLSERVER; diff --git a/jeecg-boot/jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/config/WebMvcConfiguration.java b/jeecg-boot/jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/config/WebMvcConfiguration.java index f30ba74d..699fc284 100644 --- a/jeecg-boot/jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/config/WebMvcConfiguration.java +++ b/jeecg-boot/jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/config/WebMvcConfiguration.java @@ -1,10 +1,15 @@ package org.jeecg.config; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.module.SimpleModule; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.actuate.trace.http.InMemoryHttpTraceRepository; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Configuration; +import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.UrlBasedCorsConfigurationSource; import org.springframework.web.filter.CorsFilter; @@ -12,6 +17,8 @@ import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import java.util.List; + /** * Spring Boot 2.0 解决跨域问题 * @@ -64,6 +71,22 @@ public class WebMvcConfiguration implements WebMvcConfigurer { return new CorsFilter(urlBasedCorsConfigurationSource); } + /** + * 添加Long转json精度丢失是配置 + * @Return: void + */ + @Override + public void configureMessageConverters(List> converters) { + MappingJackson2HttpMessageConverter jackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter(); + ObjectMapper objectMapper = new ObjectMapper(); + SimpleModule simpleModule = new SimpleModule(); + simpleModule.addSerializer(Long.class, ToStringSerializer.instance); + simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance); + objectMapper.registerModule(simpleModule); + jackson2HttpMessageConverter.setObjectMapper(objectMapper); + converters.add(jackson2HttpMessageConverter); + } + /** * SpringBootAdmin的Httptrace不见了 * https://blog.csdn.net/u013810234/article/details/110097201 @@ -72,4 +95,5 @@ public class WebMvcConfiguration implements WebMvcConfigurer { public InMemoryHttpTraceRepository getInMemoryHttpTrace(){ return new InMemoryHttpTraceRepository(); } + } diff --git a/jeecg-boot/pom.xml b/jeecg-boot/pom.xml index 9a4f6cf0..8dd8ccf6 100644 --- a/jeecg-boot/pom.xml +++ b/jeecg-boot/pom.xml @@ -45,6 +45,7 @@ 1.3.2 1.6.1 7.2.23 + 2.5.1