package com.gkhy.assess.framework.config;
|
|
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
|
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
import org.mybatis.spring.annotation.MapperScan;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
|
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Conditional;
|
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
import org.springframework.web.cors.CorsConfiguration;
|
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
import org.springframework.web.filter.CorsFilter;
|
|
import java.time.LocalDateTime;
|
import java.time.format.DateTimeFormatter;
|
import java.util.TimeZone;
|
|
/**
|
* 程序注解配置
|
*
|
* @author ruoyi
|
*/
|
@Configuration
|
// 表示通过aop框架暴露该代理对象,AopContext能够访问
|
@EnableAspectJAutoProxy(exposeProxy = true)
|
public class ApplicationConfig
|
{
|
|
@Value("${spring.jackson.date-format:yyyy-MM-dd HH:mm:ss}")
|
private String pattern;
|
|
/**
|
* 时区配置
|
*/
|
// @Bean
|
// public Jackson2ObjectMapperBuilderCustomizer jacksonObjectMapperCustomization()
|
// {
|
// return jacksonObjectMapperBuilder -> jacksonObjectMapperBuilder.timeZone(TimeZone.getDefault());
|
// }
|
|
/**
|
* 时间序列化
|
* @return
|
*/
|
@Bean
|
public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() {
|
return builder -> {
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
|
|
//返回时间数据序列化
|
builder.serializerByType(LocalDateTime.class, new LocalDateTimeSerializer(formatter));
|
//接收时间数据反序列化
|
builder.deserializerByType(LocalDateTime.class, new LocalDateTimeDeserializer(formatter));
|
builder.timeZone(TimeZone.getDefault());
|
};
|
}
|
|
|
@Bean
|
public CorsFilter corsFilter() {
|
final UrlBasedCorsConfigurationSource urlBasedCorsConfigurationSource = new UrlBasedCorsConfigurationSource();
|
final CorsConfiguration corsConfiguration = new CorsConfiguration();
|
//是否允许请求带有验证信息
|
corsConfiguration.setAllowCredentials(true);
|
// 允许访问的客户端域名
|
corsConfiguration.addAllowedOriginPattern("*");
|
// 允许服务端访问的客户端请求头
|
corsConfiguration.addAllowedHeader("*");
|
// 允许访问的方法名,GET POST等
|
corsConfiguration.addAllowedMethod("*");
|
urlBasedCorsConfigurationSource.registerCorsConfiguration("/**", corsConfiguration);
|
return new CorsFilter(urlBasedCorsConfigurationSource);
|
}
|
}
|