mirror of
				https://github.com/dromara/RuoYi-Vue-Plus.git
				synced 2025-11-04 08:13:44 +08:00 
			
		
		
		
	update 优化全局日期格式转换配置,提升日期参数解析兼容性
This commit is contained in:
		@@ -1,9 +1,12 @@
 | 
			
		||||
package org.dromara.common.web.config;
 | 
			
		||||
 | 
			
		||||
import cn.hutool.core.date.DateUtil;
 | 
			
		||||
import org.dromara.common.core.utils.StringUtils;
 | 
			
		||||
import org.dromara.common.web.handler.GlobalExceptionHandler;
 | 
			
		||||
import org.dromara.common.web.interceptor.PlusWebInvokeTimeInterceptor;
 | 
			
		||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
 | 
			
		||||
import org.springframework.context.annotation.Bean;
 | 
			
		||||
import org.springframework.format.FormatterRegistry;
 | 
			
		||||
import org.springframework.web.cors.CorsConfiguration;
 | 
			
		||||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
 | 
			
		||||
import org.springframework.web.filter.CorsFilter;
 | 
			
		||||
@@ -11,6 +14,8 @@ import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
 | 
			
		||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
 | 
			
		||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
 | 
			
		||||
 | 
			
		||||
import java.util.Date;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 通用配置
 | 
			
		||||
 *
 | 
			
		||||
@@ -25,6 +30,17 @@ public class ResourcesConfig implements WebMvcConfigurer {
 | 
			
		||||
        registry.addInterceptor(new PlusWebInvokeTimeInterceptor());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void addFormatters(FormatterRegistry registry) {
 | 
			
		||||
        // 全局日期格式转换配置
 | 
			
		||||
        registry.addConverter(String.class, Date.class, source -> {
 | 
			
		||||
            if (StringUtils.isBlank(source)) {
 | 
			
		||||
                return null;
 | 
			
		||||
            }
 | 
			
		||||
            return DateUtil.parse(source);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user