parent
fbcba137fa
commit
3ba93e9fb6
@ -0,0 +1,19 @@ |
||||
package com.example.demo.config; |
||||
|
||||
import org.springframework.boot.web.servlet.FilterRegistrationBean; |
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.web.filter.CharacterEncodingFilter; |
||||
|
||||
@Configuration |
||||
public class CharacterEncodingFilterConfig { |
||||
@Bean |
||||
public FilterRegistrationBean filterRegistrationBean() { |
||||
FilterRegistrationBean registrationBean = new FilterRegistrationBean(); |
||||
CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(); |
||||
characterEncodingFilter.setForceEncoding(true); |
||||
characterEncodingFilter.setEncoding("UTF-8"); |
||||
registrationBean.setFilter(characterEncodingFilter); |
||||
return registrationBean; |
||||
} |
||||
} |
@ -1,33 +0,0 @@ |
||||
package com.example.demo.config; |
||||
|
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.http.converter.HttpMessageConverter; |
||||
import org.springframework.http.converter.StringHttpMessageConverter; |
||||
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer; |
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
||||
|
||||
import java.nio.charset.StandardCharsets; |
||||
import java.util.List; |
||||
|
||||
@Configuration |
||||
public class CustomMVCConfiguration implements WebMvcConfigurer { |
||||
|
||||
|
||||
@Bean |
||||
public HttpMessageConverter<String> responseBodyConverter() { |
||||
return new StringHttpMessageConverter(StandardCharsets.UTF_8); |
||||
} |
||||
|
||||
@Override |
||||
public void configureMessageConverters( |
||||
List<HttpMessageConverter<?>> converters) { |
||||
converters.add(responseBodyConverter()); |
||||
} |
||||
|
||||
@Override |
||||
public void configureContentNegotiation( |
||||
ContentNegotiationConfigurer configurer) { |
||||
configurer.favorPathExtension(false); |
||||
} |
||||
} |
Loading…
Reference in new issue