From f6a3e11aa25cef394bcbccc8728d1e4da5a05c20 Mon Sep 17 00:00:00 2001 From: EightMonth Date: Tue, 18 Jun 2024 17:34:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AD=97=E5=85=B8=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=E9=97=AE=E9=A2=98=EF=BC=8C=E4=BF=AE=E5=A4=8D=20#6311?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/jeecg/config/WebMvcConfiguration.java | 19 +++++++++++++++++-- .../system/controller/SysDictController.java | 4 ++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/config/WebMvcConfiguration.java b/jeecg-boot-base-core/src/main/java/org/jeecg/config/WebMvcConfiguration.java index 92628df3..26f7053b 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/config/WebMvcConfiguration.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/config/WebMvcConfiguration.java @@ -12,15 +12,18 @@ import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer; import io.micrometer.prometheus.PrometheusMeterRegistry; import org.springframework.beans.factory.InitializingBean; +import org.springframework.beans.factory.ObjectProvider; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.boot.actuate.trace.http.InMemoryHttpTraceRepository; +import org.springframework.boot.autoconfigure.jackson.JacksonProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.UrlBasedCorsConfigurationSource; @@ -37,6 +40,7 @@ import java.time.LocalDateTime; import java.time.LocalTime; import java.time.format.DateTimeFormatter; import java.util.List; +import java.util.Objects; /** * Spring Boot 2.0 解决跨域问题 @@ -55,6 +59,11 @@ public class WebMvcConfiguration implements WebMvcConfigurer { @Autowired(required = false) private PrometheusMeterRegistry prometheusMeterRegistry; + @Autowired + private ObjectProvider builderProvider; + @Autowired + private JacksonProperties jacksonProperties; + /** * 静态资源的配置 - 使得可以从磁盘中读取 Html、图片、视频、音频等 */ @@ -107,6 +116,10 @@ public class WebMvcConfiguration implements WebMvcConfigurer { @Primary public ObjectMapper objectMapper() { ObjectMapper objectMapper = new ObjectMapper(); + // 继承spring jackson 默认机制 + if (Objects.nonNull(builderProvider.getIfAvailable())) { + objectMapper = builderProvider.getIfAvailable().createXmlMapper(false).build(); + } //处理bigDecimal objectMapper.enable(JsonGenerator.Feature.WRITE_BIGDECIMAL_AS_PLAIN); objectMapper.enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS); @@ -115,8 +128,10 @@ public class WebMvcConfiguration implements WebMvcConfigurer { objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); objectMapper.configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, false); objectMapper.configure(DeserializationFeature.FAIL_ON_NULL_CREATOR_PROPERTIES, false); - //默认的处理日期时间格式 - objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")); + //默认的处理日期时间格式,接受通过spring.jackson.date-format配置格式化模式 + if (Objects.isNull(jacksonProperties.getDateFormat())) { + objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")); + } JavaTimeModule javaTimeModule = new JavaTimeModule(); javaTimeModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); javaTimeModule.addSerializer(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/SysDictController.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/SysDictController.java index 0d1cf40b..d3e383c8 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/SysDictController.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/SysDictController.java @@ -503,6 +503,10 @@ public class SysDictController { QueryWrapper queryWrapper = QueryGenerator.initQueryWrapper(sysDict, request.getParameterMap()); //Step.2 AutoPoi 导出Excel ModelAndView mv = new ModelAndView(new JeecgEntityExcelView()); + String selections = request.getParameter("selections"); + if(!oConvertUtils.isEmpty(selections)){ + queryWrapper.in("id",selections.split(",")); + } List pageList = new ArrayList(); List sysDictList = sysDictService.list(queryWrapper);