| | |
| | | import org.springframework.web.cors.UrlBasedCorsConfigurationSource; |
| | | import org.springframework.web.filter.CorsFilter; |
| | | |
| | | import java.lang.reflect.Array; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.Arrays; |
| | | import java.util.TimeZone; |
| | | |
| | | /** |
| | |
| | | @Configuration |
| | | // 表示通过aop框架暴露该代理对象,AopContext能够访问 |
| | | @EnableAspectJAutoProxy(exposeProxy = true) |
| | | // 指定要扫描的Mapper类的包的路径 |
| | | @MapperScan("com.gkhy.**.mapper") |
| | | public class ApplicationConfig |
| | | { |
| | | |
| | |
| | | // return jacksonObjectMapperBuilder -> jacksonObjectMapperBuilder.timeZone(TimeZone.getDefault()); |
| | | // } |
| | | |
| | | /** |
| | | * 时间序列化 |
| | | * @return |
| | | */ |
| | | @Bean |
| | | public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() { |
| | | return builder -> { |
| | |
| | | builder.serializerByType(LocalDateTime.class, new LocalDateTimeSerializer(formatter)); |
| | | //接收时间数据反序列化 |
| | | builder.deserializerByType(LocalDateTime.class, new LocalDateTimeDeserializer(formatter)); |
| | | builder.timeZone(TimeZone.getDefault()); |
| | | builder.timeZone(TimeZone.getTimeZone("UTC+8")); |
| | | }; |
| | | } |
| | | |
| | |
| | | @Bean |
| | | public CorsFilter corsFilter() { |
| | | final UrlBasedCorsConfigurationSource urlBasedCorsConfigurationSource = new UrlBasedCorsConfigurationSource(); |
| | | final CorsConfiguration corsConfiguration = new CorsConfiguration(); |
| | | final CorsConfiguration config = new CorsConfiguration(); |
| | | //是否允许请求带有验证信息 |
| | | corsConfiguration.setAllowCredentials(true); |
| | | config.setAllowCredentials(true); |
| | | config.setAllowedOrigins(Arrays.asList("*")); |
| | | config.setAllowedMethods(Arrays.asList("*")); |
| | | config.setAllowCredentials(true); |
| | | config.setMaxAge(168000L); |
| | | |
| | | // 允许访问的客户端域名 |
| | | corsConfiguration.addAllowedOriginPattern("*"); |
| | | // 允许服务端访问的客户端请求头 |
| | | corsConfiguration.addAllowedHeader("*"); |
| | | // 允许访问的方法名,GET POST等 |
| | | corsConfiguration.addAllowedMethod("*"); |
| | | urlBasedCorsConfigurationSource.registerCorsConfiguration("/**", corsConfiguration); |
| | | // config.addAllowedOriginPattern("*"); |
| | | // // 允许服务端访问的客户端请求头 |
| | | // config.addAllowedHeader("*"); |
| | | // // 允许访问的方法名,GET POST等 |
| | | // config.addAllowedMethod("*"); |
| | | urlBasedCorsConfigurationSource.registerCorsConfiguration("/**", config); |
| | | return new CorsFilter(urlBasedCorsConfigurationSource); |
| | | } |
| | | } |