乱码原因:
@ResponseBody注解把返回值直接写到HTTP response body里,spring注解的默认编码是iso-8859-1,而我的工程编码和页面都是utf-8,所以乱码。
解决方案:
在springmvc的配置文件中加入如下代码:
< !-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射 -->
< bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" >
< property name="messageConverters">
<list>
<bean class = "org.springframework.http.converter.StringHttpMessageConverter">
<property name = "supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value>
</list>
</property>
</bean>
</list>
</property>
< /bean>
就可以解决了!