1.返回给前端的字符是??,乱码
在springMVC配置文件中加入
<mvc:annotation-driven >
<mvc:message-converters register-defaults="true">
<bean class="org.springframework.http.converter.StringHttpMessageConverter" >
<property name = "supportedMediaTypes">
<list>
<value>application/json;charset=utf-8</value>
<value>text/html;charset=utf-8</value>
<!-- application 可以在任意 form 表单里面 enctype 属性默认找到 -->
<value>application/x-www-form-urlencoded</value>
</list>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
不要忘记配置文件中扫描器
<!--配置springmvc注解扫描-->
<context:component-scan base-package="com.yiyezhiqiu.controller"/>
<!--配置不处理静态资源-->
<mvc:default-servlet-handler/>
<!--配置注解驱动-->
<mvc:annotation-driven />
2.前端页面乱码
修改tomcat/conf/service.xml文件中的配置
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="UTF-8" />
本文介绍了解决Spring MVC项目中出现的字符乱码问题的方法,包括配置文件中的设置及Tomcat服务端口URI编码调整。

403

被折叠的 条评论
为什么被折叠?



