新增 lang.defaultLocale 和 lang.defaultTimeZone

指定默认语言和默认时区参数(解决某些linux下的国际化的问题)
This commit is contained in:
thinkgem
2019-02-03 21:58:09 +08:00
parent e1d47099b6
commit 006d34792f
5 changed files with 19 additions and 5 deletions

View File

@@ -26,6 +26,7 @@ import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.util.JSONPObject;
import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule;
import com.jeesite.common.collect.ListUtils;
import com.jeesite.common.io.PropertiesUtils;
/**
* 简单封装Jackson实现JSON String<->Java Object的Mapper.
@@ -55,8 +56,9 @@ public class JsonMapper extends ObjectMapper {
this.configure(Feature.ALLOW_SINGLE_QUOTES, true);
// 允许不带引号的字段名称
this.configure(Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
// 设置时区
this.setTimeZone(TimeZone.getTimeZone("GMT+8:00"));
// 设置默认时区
this.setTimeZone(TimeZone.getTimeZone(PropertiesUtils.getInstance()
.getProperty("lang.defaultTimeZone", "GMT+08:00")));
// 设置输入时忽略在JSON字符串中存在但Java对象实际没有的属性
this.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
// 遇到空值处理为空串

View File

@@ -24,6 +24,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import com.fasterxml.jackson.databind.JavaType;
import com.jeesite.common.io.PropertiesUtils;
/**
* XML <-> Map、Object
@@ -49,8 +50,9 @@ public class XmlMapper extends com.fasterxml.jackson.dataformat.xml.XmlMapper{
public XmlMapper() {
// Spring ObjectMapper 初始化配置,支持 @JsonView
new Jackson2ObjectMapperBuilder().configure(this);
// 设置时区
this.setTimeZone(TimeZone.getTimeZone("GMT+8:00"));
// 设置默认时区
this.setTimeZone(TimeZone.getTimeZone(PropertiesUtils.getInstance()
.getProperty("lang.defaultTimeZone", "GMT+08:00")));
}
/**

View File

@@ -203,7 +203,12 @@ menu:
# 国际化管理(专业版)
lang:
enabled: false
# 默认语言
defaultLocale: zh_CN
# 默认时区
defaultTimeZone: GMT+08:00
# 任务调度(个人版)
job:
enabled: false

View File

@@ -256,6 +256,11 @@ logging:
# 国际化管理(专业版)
#lang:
# enabled: false
#
# # 默认语言
# defaultLocale: zh_CN
# # 默认时区
# defaultTimeZone: GMT+08:00
# 任务调度(个人版)
#job: