第一种、注解
@RequestMapping(value = "/test.do", method = {RequestMethod.GET},produces = "text/plain;charset=utf-8")
@ResponseBody
public String test(HttpServletResponse response) {
}
第二种、spring mvc 配置文件
<!-- 会自动注册DefaultAnnotationHandlerMapping与AnnotationMethodHandlerAdapter
两个bean -->
<mvc:annotation-driven>
<!-- Springmvc处理@responsebody 使用的是默认编码iso-8859-1 所以改变编码 -->
<mvc:message-converters>
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<constructor-arg name="defaultCharset" value="UTF-8"></constructor-arg>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>