标签:ddc red uil pretty ... -- ams name erro
@Configuration
public class WebAppConfig implements WebMvcConfigurer{
@Bean
public HandlerInterceptor getLoginInterceptor(){
return new LoginInterceptor();
}
@Override
public void addInterceptors(InterceptorRegistry registry){
registry.addInterceptor(getLoginInterceptor())
.addPathPatterns("/**")
.excludePathPatterns("/error")
.excludePathPatterns("/static/*");
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry){
registry.addResourceHandler("/static/**")
.addResourceLocations("classpath:/static/");
}
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")//设置允许跨域的路径
.allowedOrigins("*")//设置允许跨域请求的域名
.allowCredentials(true)//是否允许证书 不再默认开启
.allowedMethods("GET", "POST", "PUT", "DELETE")//设置允许的方法
.maxAge(3600);//跨域允许时间
}
}
使用这个在升级springboot2.0之后会把Date类型字段自动给转成UTC字符串 如:1990-11-26T16:00:00.000+0000,如果想转成时间戳在application.properties配置文件增加以下配置:
spring.jackson.serialization.write-dates-as-timestamps=true
spring.jackson.time-zone=GMT+8
@Configuration
public class WebAppConfig extends WebMvcConfigurationSupport{
...
}
这种方式会把Date类型字段自动给转成时间戳,如果想用UTC字符串,在application.properties配置文件增加以下配置:
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8
Spring Boot2.0的版本(IDEA创建的时候自动选择的这个版本),然后编译器告诉我WebMvcConfigurerAdapter已过时了
@Deprecated
public abstract class WebMvcConfigurerAdapter implements WebMvcConfigurer {
/**
* {@inheritDoc}
* <p>This implementation is empty.
*/
@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
}
@Configuration
public class WebMvcConfg implements WebMvcConfigurer {
//省略
}
推荐 WebMvcConfigurationSupport
@Configuration
public class WebMvcConfg extends WebMvcConfigurationSupport {
//省略
}
spring boot 2.0 WebMvcConfigurerAdapter过时解决方法
标签:ddc red uil pretty ... -- ams name erro
原文地址:https://www.cnblogs.com/exmyth/p/10743378.html