|
@@ -1,26 +1,43 @@
|
|
|
package com.ruoyi.framework.config;
|
|
|
|
|
|
-import java.util.concurrent.TimeUnit;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.fasterxml.jackson.core.JsonGenerator;
|
|
|
+import com.fasterxml.jackson.databind.JsonSerializer;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import com.fasterxml.jackson.databind.SerializerProvider;
|
|
|
+import com.fasterxml.jackson.databind.module.SimpleModule;
|
|
|
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
|
|
+import com.ruoyi.common.config.RuoYiConfig;
|
|
|
+import com.ruoyi.common.constant.Constants;
|
|
|
+import com.ruoyi.common.utils.PageWrapper;
|
|
|
+import com.ruoyi.framework.interceptor.RepeatSubmitInterceptor;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
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.MappingJackson2HttpMessageConverter;
|
|
|
import org.springframework.web.cors.CorsConfiguration;
|
|
|
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
|
|
import org.springframework.web.filter.CorsFilter;
|
|
|
+import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
|
|
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 com.ruoyi.common.config.RuoYiConfig;
|
|
|
-import com.ruoyi.common.constant.Constants;
|
|
|
-import com.ruoyi.framework.interceptor.RepeatSubmitInterceptor;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.List;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
|
* 通用配置
|
|
|
*
|
|
|
* @author ruoyi
|
|
|
*/
|
|
|
+@EnableWebMvc
|
|
|
@Configuration
|
|
|
+@SuppressWarnings({"unchecked", "rawtypes"})
|
|
|
public class ResourcesConfig implements WebMvcConfigurer
|
|
|
{
|
|
|
@Autowired
|
|
@@ -70,4 +87,32 @@ public class ResourcesConfig implements WebMvcConfigurer
|
|
|
// 返回新的CorsFilter
|
|
|
return new CorsFilter(source);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * webMvc序列化
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
|
|
|
+
|
|
|
+ MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
|
|
|
+
|
|
|
+ ObjectMapper objectMapper = converter.getObjectMapper()
|
|
|
+ // 时间格式化
|
|
|
+ .setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"))
|
|
|
+ .registerModule(new SimpleModule()
|
|
|
+ // 将Long转换成String
|
|
|
+ .addSerializer(Long.class, ToStringSerializer.instance)
|
|
|
+ // 将Page转成PageWrapper
|
|
|
+ .addSerializer(IPage.class, new JsonSerializer<IPage>() {
|
|
|
+ @Override
|
|
|
+ public void serialize(IPage page, JsonGenerator jg, SerializerProvider sp) throws IOException {
|
|
|
+ jg.writeObject(new PageWrapper(page));
|
|
|
+ }
|
|
|
+ })
|
|
|
+ );
|
|
|
+
|
|
|
+ converter.setObjectMapper(objectMapper);
|
|
|
+ converters.add(converter);
|
|
|
+ }
|
|
|
+
|
|
|
}
|