code optimization
This commit is contained in:
@@ -74,15 +74,13 @@ public class JsonMapper extends ObjectMapper {
|
|||||||
public JsonMapper setLocaleTimeZoneDateFormat(){
|
public JsonMapper setLocaleTimeZoneDateFormat(){
|
||||||
PropertiesUtils props = PropertiesUtils.getInstance();
|
PropertiesUtils props = PropertiesUtils.getInstance();
|
||||||
// 设置默认语言环境
|
// 设置默认语言环境
|
||||||
String defaultLocale = props.getProperty("lang.defaultLocale");
|
props.getPropertyIfNotBlank("lang.defaultLocale", (defaultLocale) -> {
|
||||||
if (StringUtils.isNotBlank(defaultLocale)) {
|
|
||||||
this.setLocale(LocaleUtils.toLocale(defaultLocale));
|
this.setLocale(LocaleUtils.toLocale(defaultLocale));
|
||||||
}
|
});
|
||||||
// 设置默认时区
|
// 设置默认时区
|
||||||
String defaultTimeZone = props.getProperty("lang.defaultTimeZone");
|
props.getPropertyIfNotBlank("lang.defaultTimeZone", (defaultTimeZone) -> {
|
||||||
if (StringUtils.isNotBlank(defaultTimeZone)) {
|
|
||||||
this.setTimeZone(TimeZone.getTimeZone(defaultTimeZone));
|
this.setTimeZone(TimeZone.getTimeZone(defaultTimeZone));
|
||||||
}
|
});
|
||||||
this.setAnnotationIntrospector(new JacksonAnnotationIntrospector() {
|
this.setAnnotationIntrospector(new JacksonAnnotationIntrospector() {
|
||||||
@Serial
|
@Serial
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|||||||
@@ -40,15 +40,13 @@ public class XmlMapper extends com.fasterxml.jackson.dataformat.xml.XmlMapper{
|
|||||||
public XmlMapper() {
|
public XmlMapper() {
|
||||||
PropertiesUtils props = PropertiesUtils.getInstance();
|
PropertiesUtils props = PropertiesUtils.getInstance();
|
||||||
// 设置默认语言环境
|
// 设置默认语言环境
|
||||||
String defaultLocale = props.getProperty("lang.defaultLocale");
|
props.getPropertyIfNotBlank("lang.defaultLocale", (defaultLocale) -> {
|
||||||
if (StringUtils.isNotBlank(defaultLocale)) {
|
|
||||||
this.setLocale(LocaleUtils.toLocale(defaultLocale));
|
this.setLocale(LocaleUtils.toLocale(defaultLocale));
|
||||||
}
|
});
|
||||||
// 设置默认时区
|
// 设置默认时区
|
||||||
String defaultTimeZone = props.getProperty("lang.defaultTimeZone");
|
props.getPropertyIfNotBlank("lang.defaultTimeZone", (defaultTimeZone) -> {
|
||||||
if (StringUtils.isNotBlank(defaultTimeZone)) {
|
|
||||||
this.setTimeZone(TimeZone.getTimeZone(defaultTimeZone));
|
this.setTimeZone(TimeZone.getTimeZone(defaultTimeZone));
|
||||||
}
|
});
|
||||||
// Spring ObjectMapper 初始化配置,支持 @JsonView
|
// Spring ObjectMapper 初始化配置,支持 @JsonView
|
||||||
new Jackson2ObjectMapperBuilder().configure(this);
|
new Jackson2ObjectMapperBuilder().configure(this);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,12 +15,10 @@ import jakarta.servlet.http.HttpServletResponse;
|
|||||||
*/
|
*/
|
||||||
public class ResultUtils {
|
public class ResultUtils {
|
||||||
|
|
||||||
private static final boolean isDefaultResult = PropertiesUtils.getInstance()
|
private static final PropertiesUtils props = PropertiesUtils.getInstance();
|
||||||
.getPropertyToBoolean("web.isDefaultResult", "false");
|
private static final boolean isDefaultResult = props.getPropertyToBoolean("web.isDefaultResult", "false");
|
||||||
private static final String resultParamName = PropertiesUtils.getInstance()
|
private static final String resultParamName = props.getProperty("web.resultParamName", "__data");
|
||||||
.getProperty("web.resultParamName", "__data");
|
private static final String headerParamName = props.getProperty("web.headerParamName", "x-data");
|
||||||
private static final String headerParamName = PropertiesUtils.getInstance()
|
|
||||||
.getProperty("web.headerParamName", "x-data");
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置 web.isResult 参数可强制全局使用统一结果输出,否则,传递 __data=true 参数,或 x-data 请求头为 true 时启用
|
* 设置 web.isResult 参数可强制全局使用统一结果输出,否则,传递 __data=true 参数,或 x-data 请求头为 true 时启用
|
||||||
|
|||||||
Reference in New Issue
Block a user