From 93a9eadd0edbff1f7fcc5a247c97c76a9e9a03e0 Mon Sep 17 00:00:00 2001
From: maven <2163098428@qq.com>
Date: 星期日, 28 九月 2025 14:41:08 +0800
Subject: [PATCH] yys 修改配置文件
---
ruoyi-framework/src/main/java/com/ruoyi/framework/config/ResourcesConfig.java | 75 ++++++++++++++++++++++++++++++-------
1 files changed, 61 insertions(+), 14 deletions(-)
diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/ResourcesConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/ResourcesConfig.java
index 3900552..11e3b57 100644
--- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/ResourcesConfig.java
+++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/ResourcesConfig.java
@@ -1,10 +1,25 @@
package com.ruoyi.framework.config;
+import java.text.SimpleDateFormat;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.List;
import java.util.concurrent.TimeUnit;
+
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
+import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
+import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.CacheControl;
+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;
import org.springframework.web.filter.CorsFilter;
@@ -17,34 +32,41 @@
/**
* 閫氱敤閰嶇疆
- *
+ *
* @author ruoyi
*/
@Configuration
-public class ResourcesConfig implements WebMvcConfigurer
-{
+public class ResourcesConfig implements WebMvcConfigurer {
@Autowired
private RepeatSubmitInterceptor repeatSubmitInterceptor;
+ @Value("${file.path}")
+ private String filePath;
+
+ @Value("${wordUrl}")
+ private String wordUrl;
+
@Override
- public void addResourceHandlers(ResourceHandlerRegistry registry)
- {
+ public void addResourceHandlers(ResourceHandlerRegistry registry) {
/** 鏈湴鏂囦欢涓婁紶璺緞 */
registry.addResourceHandler(Constants.RESOURCE_PREFIX + "/**")
.addResourceLocations("file:" + RuoYiConfig.getProfile() + "/");
- /** swagger閰嶇疆 */
- registry.addResourceHandler("/swagger-ui/**")
- .addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/")
- .setCacheControl(CacheControl.maxAge(5, TimeUnit.HOURS).cachePublic());
+
+ registry.addResourceHandler("/doc.html").addResourceLocations("classpath:/META-INF/resources/");
+ registry.addResourceHandler("/favicon.ico").addResourceLocations("classpath:/META-INF/resources/");
+ registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
+
+ //璁剧疆鏂囦欢铏氭嫙璺緞鏄犲皠
+ registry.addResourceHandler("/img/**").addResourceLocations("file:" + filePath + "/");
+ registry.addResourceHandler("/word/**").addResourceLocations("file:" + wordUrl + "/");
}
/**
* 鑷畾涔夋嫤鎴鍒�
*/
@Override
- public void addInterceptors(InterceptorRegistry registry)
- {
+ public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(repeatSubmitInterceptor).addPathPatterns("/**");
}
@@ -52,8 +74,7 @@
* 璺ㄥ煙閰嶇疆
*/
@Bean
- public CorsFilter corsFilter()
- {
+ public CorsFilter corsFilter() {
CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(true);
// 璁剧疆璁块棶婧愬湴鍧�
@@ -70,4 +91,30 @@
// 杩斿洖鏂扮殑CorsFilter
return new CorsFilter(source);
}
-}
\ No newline at end of file
+
+ // 鍏ㄥ眬鏍煎紡鍖栧鐞�
+ @Override
+ public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
+ String dateFormat = "yyyy-MM-dd HH:mm:ss";
+
+ Jackson2ObjectMapperBuilder json = Jackson2ObjectMapperBuilder.json();
+ MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
+
+ //localDateTime鏍煎紡鍖�
+ JavaTimeModule module = new JavaTimeModule();
+ LocalDateTimeDeserializer dateTimeDeserializer = new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern(dateFormat));
+ LocalDateTimeSerializer dateTimeSerializer = new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(dateFormat));
+ module.addDeserializer(LocalDateTime.class, dateTimeDeserializer);
+ module.addSerializer(LocalDateTime.class, dateTimeSerializer);
+ ObjectMapper objectMapper = json.modules(module)
+ .featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS).build();
+
+ //date鏃堕棿鏍煎紡鍖�
+ objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ objectMapper.setDateFormat(new SimpleDateFormat(dateFormat.split(" ")[0]));
+
+ // 璁剧疆鏍煎紡鍖栧唴瀹�
+ converter.setObjectMapper(objectMapper);
+ converters.add(0, converter);
+ }
+}
--
Gitblit v1.9.3