Commit 87630ecd9271e74fe0e008371588d0f61e151ea3

Authored by zhangdaiscott
1 parent dbdc5868

上传文件中文文件名转为拼音、Long类型精度丢失问题 issues/I24KXI、达梦数据库兼容修改

jeecg-boot/jeecg-boot-base/jeecg-boot-base-core/pom.xml
... ... @@ -76,6 +76,12 @@
76 76 <version>${commons.version}</version>
77 77 </dependency>
78 78  
  79 + <!-- 拼音库 -->
  80 + <dependency>
  81 + <groupId>com.belerweb</groupId>
  82 + <artifactId>pinyin4j</artifactId>
  83 + <version>${pinyin4j.version}</version>
  84 + </dependency>
79 85 <!-- freemarker -->
80 86 <dependency>
81 87 <groupId>org.springframework.boot</groupId>
... ...
jeecg-boot/jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/CommonUtils.java
1 1 package org.jeecg.common.util;
2 2  
  3 +import cn.hutool.core.util.StrUtil;
  4 +import cn.hutool.extra.pinyin.PinyinUtil;
3 5 import lombok.extern.slf4j.Slf4j;
4 6 import org.jeecg.common.constant.CommonConstant;
5 7 import org.jeecg.common.constant.DataBaseConstant;
... ... @@ -16,10 +18,15 @@ import java.io.InputStream;
16 18 import java.sql.Connection;
17 19 import java.sql.DatabaseMetaData;
18 20 import java.sql.SQLException;
  21 +import java.util.regex.Matcher;
  22 +import java.util.regex.Pattern;
19 23  
20 24 @Slf4j
21 25 public class CommonUtils {
22 26  
  27 + //中文正则
  28 + private static Pattern ZHONGWEN_PATTERN = Pattern.compile("[\u4e00-\u9fa5]");
  29 +
23 30 public static String uploadOnlineImage(byte[] data,String basePath,String bizPath,String uploadType){
24 31 String dbPath = null;
25 32 String fileName = "image" + Math.round(Math.random() * 100000000000L);
... ... @@ -68,9 +75,28 @@ public class CommonUtils {
68 75 }
69 76 //替换上传文件名字的特殊字符
70 77 fileName = fileName.replace("=","").replace(",","").replace("&","").replace("#", "");
  78 + //替换上传文件名字中的中文
  79 + if(ifContainChinese(fileName)){
  80 + fileName= PinyinUtil.getPinyin(fileName, StrUtil.EMPTY);
  81 + }
  82 + //替换上传文件名字中的空格
  83 + fileName=fileName.replaceAll("\\s","");
71 84 return fileName;
72 85 }
73 86  
  87 + // java 判断字符串里是否包含中文字符
  88 + public static boolean ifContainChinese(String str) {
  89 + if(str.getBytes().length == str.length()){
  90 + return false;
  91 + }else{
  92 + Matcher m = ZHONGWEN_PATTERN.matcher(str);
  93 + if (m.find()) {
  94 + return true;
  95 + }
  96 + return false;
  97 + }
  98 + }
  99 +
74 100 /**
75 101 * 统一全局上传
76 102 * @Return: java.lang.String
... ... @@ -129,7 +155,7 @@ public class CommonUtils {
129 155 String dbType = md.getDatabaseProductName().toLowerCase();
130 156 if(dbType.indexOf("mysql")>=0) {
131 157 DB_TYPE = DataBaseConstant.DB_TYPE_MYSQL;
132   - }else if(dbType.indexOf("oracle")>=0) {
  158 + }else if(dbType.indexOf("oracle")>=0 ||dbType.indexOf("dm")>=0) {
133 159 DB_TYPE = DataBaseConstant.DB_TYPE_ORACLE;
134 160 }else if(dbType.indexOf("sqlserver")>=0||dbType.indexOf("sql server")>=0) {
135 161 DB_TYPE = DataBaseConstant.DB_TYPE_SQLSERVER;
... ...
jeecg-boot/jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/config/WebMvcConfiguration.java
1 1 package org.jeecg.config;
2 2  
  3 +import com.fasterxml.jackson.databind.ObjectMapper;
  4 +import com.fasterxml.jackson.databind.module.SimpleModule;
  5 +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
3 6 import org.springframework.beans.factory.annotation.Value;
4 7 import org.springframework.boot.actuate.trace.http.InMemoryHttpTraceRepository;
5 8 import org.springframework.context.annotation.Bean;
6 9 import org.springframework.context.annotation.Conditional;
7 10 import org.springframework.context.annotation.Configuration;
  11 +import org.springframework.http.converter.HttpMessageConverter;
  12 +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
8 13 import org.springframework.web.cors.CorsConfiguration;
9 14 import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
10 15 import org.springframework.web.filter.CorsFilter;
... ... @@ -12,6 +17,8 @@ import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
12 17 import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
13 18 import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
14 19  
  20 +import java.util.List;
  21 +
15 22 /**
16 23 * Spring Boot 2.0 解决跨域问题
17 24 *
... ... @@ -65,6 +72,22 @@ public class WebMvcConfiguration implements WebMvcConfigurer {
65 72 }
66 73  
67 74 /**
  75 + * 添加Long转json精度丢失是配置
  76 + * @Return: void
  77 + */
  78 + @Override
  79 + public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
  80 + MappingJackson2HttpMessageConverter jackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();
  81 + ObjectMapper objectMapper = new ObjectMapper();
  82 + SimpleModule simpleModule = new SimpleModule();
  83 + simpleModule.addSerializer(Long.class, ToStringSerializer.instance);
  84 + simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance);
  85 + objectMapper.registerModule(simpleModule);
  86 + jackson2HttpMessageConverter.setObjectMapper(objectMapper);
  87 + converters.add(jackson2HttpMessageConverter);
  88 + }
  89 +
  90 + /**
68 91 * SpringBootAdmin的Httptrace不见了
69 92 * https://blog.csdn.net/u013810234/article/details/110097201
70 93 */
... ... @@ -72,4 +95,5 @@ public class WebMvcConfiguration implements WebMvcConfigurer {
72 95 public InMemoryHttpTraceRepository getInMemoryHttpTrace(){
73 96 return new InMemoryHttpTraceRepository();
74 97 }
  98 +
75 99 }
... ...
jeecg-boot/pom.xml
... ... @@ -45,6 +45,7 @@
45 45 <justauth-spring-boot-starter.version>1.3.2</justauth-spring-boot-starter.version>
46 46 <dom4j.version>1.6.1</dom4j.version>
47 47 <qiniu-java-sdk.version>7.2.23</qiniu-java-sdk.version>
  48 + <pinyin4j.version>2.5.1</pinyin4j.version>
48 49 </properties>
49 50  
50 51 <modules>
... ...