乱码原因:StringHttpMessageConverter的默认编码是ISO-8859-1

 

 

 

而json的转化起编码默认是utf-8:

 

解决方法:

1.在Controller里添加@RequestMapping(value="ajax",produces = "text/html;charset=UTF-8")

 

2.在springMVC的加载驱动里的mvc:message-converters标签修改StringHttpMessageConverter默认编码

       <mvc:annotation-driven>

              <mvc:message-converters>

                     <bean class="org.springframework.http.converter.StringHttpMessageConverter">

                            <constructor-arg index="0" value="utf-8"></constructor-arg>

                     </bean>

              </mvc:message-converters>

       </mvc:annotation-driven>

posted on 2019-09-03 22:04  kfsrex  阅读(506)  评论(0编辑  收藏  举报