spring+mybatis 通过@ResponseBody返回结果中文乱码的解决方法

网友投稿 339 2023-03-05


spring+mybatis 通过@ResponseBody返回结果中文乱码的解决方法

问题发生:

通过@Responsebody返回

@ResponseBody

@RequestMapping(value ="/selectByFormId",method = RequestMethod.GET)

public Map getClassName(String formId){

http://List list =formInfoService.selectClassName(formId);

Map map = new HashMap();

map.put("data", list);

map.put("status", true);

return map;

}

结果:

{"data":["璧勮璇疯喘绫�","淇冮攢绫�","绠$悊绫�","鏆傛敮绫�","鍌ㄨ繍绫�","璧勪骇绫�","璧勮鏈嶅姟绫�","宸梾绠$悊绫�",
"閲囪喘绫�","浜轰簨鑰冨嫟绫�","璐㈠姟绫�","瀹㈡埛绫�","瑙嗘嫇绫�","瀹㈣瘔绫�","浜轰簨娲诲姩绫�","浜轰簨琛屾斂绫�","鍏枃绫�",
"璇锋绫�","閿?绠$被","钀ヨ繍涓氬姟绫�"],"status":true}

解决办法:

在spring-mvc.xml中配置

但是配置完后又有了新的问题

error:...cvc-complex-type.2.1: 元素 'mvc:annotation-driven' 必须不含字符或元素信息项 [子级], 因为该类型的内容类型为空。

后来知道是 springMVC的XSD文件版本不对,换成springMVC 4.0的 XSD就可以了

xmlns:xsi="http://w3.org/2001/XMLSchema-instance" xmlns:p="http://springframework.org/schema/p"

xmlns:context="http://springframework.org/schema/context"

xmlns:mvc="http://springframework.org/schema/mvc"

xsi:schemaLocation="http://springframework.org/schema/beans

http://springframework.org/schema/beans/spring-beans-3.1.xsd

http://springframework.org/schema/context

http://springframework.org/schema/context/spring-context-3.1.xsd

http://springframework.org/schema/mvc

http://springframework.org/schema/mvc/spring-mvc-4.0.xsd">

然后就ok了

{"data":["资讯请购类","促销类","管理类","暂支类","储运类","资产类","资讯服务类","差旅管理类","采购类","人事考勤类"
,"财务类","客户类","视拓类","客诉类","人事活动类","人事行政类","公文类","请款类","销管类","营运业务类"],"statnbYlcTUQIXus":true}

StringHttpMessageConverter 这个方法 有很多转换作用,有时间可以多看看

xmlns:xsi="http://w3.org/2001/XMLSchema-instance" xmlns:p="http://springframework.org/schema/p"

xmlns:context="http://springframework.org/schema/context"

xmlns:mvc="http://springframework.org/schema/mvc"

xsi:schemaLocation="http://springframework.org/schema/beans

http://springframework.org/schema/beans/spring-beans-3.1.xsd

http://springframework.org/schema/context

http://springframework.org/schema/context/spring-context-3.1.xsd

http://springframework.org/schema/mvc

http://springframework.org/schema/mvc/spring-mvc-4.0.xsd">

然后就ok了

{"data":["资讯请购类","促销类","管理类","暂支类","储运类","资产类","资讯服务类","差旅管理类","采购类","人事考勤类"
,"财务类","客户类","视拓类","客诉类","人事活动类","人事行政类","公文类","请款类","销管类","营运业务类"],"statnbYlcTUQIXus":true}

StringHttpMessageConverter 这个方法 有很多转换作用,有时间可以多看看


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:基于自定义BufferedReader中的read和readLine方法
下一篇:在线api接口管理平台(在线api接口调试工具)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~