Json乱码问题

    <!--自动扫描指定的包, 下面所有的注解类交给IOC容器管理 -->
    <context:component-scan base-package="top.withlevi.controller"/>

    <!--视图解析器-->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" id="internalResourceViewResolver">
        <!--前缀-->
        <property name="prefix" value="/WEB-INF/jsp/"/>
        <!--后缀-->
        <property name="suffix" value=".jsp"/>
    </bean>

    <!--解决Json乱码问题-->
    <mvc:annotation-driven>
        <mvc:message-converters register-defaults="true">
            <bean class="org.springframework.http.converter.StringHttpMessageConverter">
                <constructor-arg value="UTF-8"/>
            </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"/>
                         </bean>
                    </property>
            </bean>
        </mvc:message-converters>
    </mvc:annotation-driven>
posted @ 2021-09-11 10:59  withLevi  阅读(70)  评论(0编辑  收藏  举报