第一种:在@RequestMapping中添加produces="text/html;charset=UTF-8
@ResponseBody
@RequestMapping(value = "/hello",produces = "produces=text/html;charset=UTF-8")
public String hello(){
List<Employee> l = employeeDao.findAll();
System.out.println(l.toString());
return l.toString();
}
第二种:在配置文件中的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>
最后
以上就是个性飞机最近收集整理的关于解决SpringMVC的@ResponseBody返回中文乱码的全部内容,更多相关解决SpringMVC内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复