admin管理员组文章数量:1794759
spring mvc4 restful api 乱码问题
一,修改spring-mvc.xml
添加如下:
<mvc:annotation-driven> <mvc:message-converters register-defaults="true"> <!-- 将StringHttpMessageConverter的默认编码设为UTF-8 --> <bean class="org.springframework.http.converter.StringHttpMessageConverter"> <constructor-arg value="UTF-8" /> <property name="supportedMediaTypes" value="text/html;charset=UTF-8" /> </bean> <!-- 将Jackson2HttpMessageConverter的默认格式化输出设为true --> <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"> <property name="prettyPrint" value="true" /> <property name="supportedMediaTypes" value="text/html;charset=UTF-8" /> </bean> </mvc:message-converters> </mvc:annotation-driven> 二,修改方法,添加编码 @RequestMapping(value = "/get/{msg}", produces = "application/json;charset=UTF-8", method = RequestMethod.GET) @ResponseBody public String get(@PathVariable("msg") String msg) { String result = "[GET] Hello " + msg; return result; }版权声明:本文标题:spring mvc4 restful api 乱码问题 内容由林淑君副主任自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.xiehuijuan.com/baike/1686614710a86387.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论