在練習SSM整合案例,后台進行更新和刪除時,直接返回了json字符串給前台頁面
但是前台頁面會顯示問號
此時已經在web.xml中配置了編碼過濾器,但還是會出現亂碼
最后發現通過以下方式可以解決問題:
在springmvc配置文件中的注解驅動 <mvc:annotation-driven>中加入以下配置
<mvc:annotation-driven>
<mvc:message-converters register-defaults="true">
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes" value="text/html;charset=UTF-8"/>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>