@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**").allowedOrigins("*").allowedMethods("GET", "POST", "OPTIONS", "PUT")
.allowedHeaders(
"Content-Type",
"X-Requested-With",
"accept", "Origin",
"Access-Control-Request-Method",
"Access-Control-Request-Headers"
)
.exposedHeaders("Access-Control-Allow-Origin", "Access-Control-Allow-Credentials")
.allowCredentials(true).maxAge(3600);
}
// @Bean
// public HttpMessageConverters fastJsonHttpMessageConverters() {
// //1.Need to define an object that converts the message// FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
// //2.Add fastjson configuration information, such as whether to format the returned json data// FastJsonConfig fastJsonConfig = new FastJsonConfig();
// fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);
// fastJsonConfig.setCharset(Charset.forName("UTF-8"));
// //3.Add configuration information in convert// fastConverter.setFastJsonConfig(fastJsonConfig);
//
// HttpMessageConverter<?> converter = fastConverter;
// return new HttpMessageConverters(converter);
// }
}