spring 版本: 4.3.7 addFormatters(FormatterRegistry registry)
不生效
<!-- 此处与 @EnableWebmvc 冲突, 配置此处后 EnableWebmvc 中的配置无效 -->
<mvc:annotation-driven content-negotiation-manager="contentNegotiationManager">
<mvc:message-converters>
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<constructor-arg value="UTF-8"/>
</bean>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>application/json;charset=UTF-8</value>
<value>text/plain;charset=utf-8</value>
<value>text/html;charset=UTF-8</value>
<value>text/json;charset=UTF-8</value>
<value>text/html;charset=ISO-8859-1</value>
<value>application/x-www-form-urlencoded;charset=UTF-8</value>
</list>
</property>
<property name="prettyPrint" value="false"></property>
<property name="objectMapper">
<bean class="com.we.core.web.view.JsonMapper">
<property name="dateFormat">
<bean class="java.text.SimpleDateFormat">
<constructor-arg type="java.lang.String" value="yyyy-MM-dd HH:mm:ss"/>
</bean>
</property>
</bean>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
@Configuration
@EnableWebMvc
public class WebAppConfig extends WebMvcConfigurerAdapter {
@Override
public void addFormatters(FormatterRegistry registry) {
super.addFormatters(registry);
registry.addConverterFactory(new StrValueToEnumConverterFactory());
}
}
暂时不清楚是 spring 设计如此 还是 bug
标签:UTF,spring,charset,addFormatters,mvc,registry,text,Configuration From: https://www.cnblogs.com/whm-blog/p/16873894.html