Solution to the JSON garbled problem in the SSM project

Add the following content to spring-mvc.xml or other configuration files that configure springxxx-xxxxmvc.xml to filter out garbled characters

 <!--**json乱码问题配置解决方法**-->
            <mvc:annotation-driven>
                <mvc:message-converters>
                    <bean class="org.springframework.http.converter.StringHttpMessageConverter">
                        <constructor-arg value="UTF-8"></constructor-arg>
                    </bean>
                    <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
                        <property name="objectMapper">
                            <bean class="org.springframework.http.converter.json.Jackson2ObjectMapperFactoryBean">
                                <property name="failOnEmptyBeans" value="false"></property>
                            </bean>
                        </property>
                    </bean>
                </mvc:message-converters>
            </mvc:annotation-driven>

Guess you like

Origin blog.csdn.net/qq_34134299/article/details/114043449