天天看点

解决@ResponseBody出现乱码以及返回List集合出现406问题

1.首先是乱码问题:

@RequestMapping(value = "/path",method = RequestMethod.GET,produces="text/plain;charset=UTF-8")      

这个还是比较好的,当然啊如果是返回List集合的话,在你的springmvc配置文件中加上这个:

<!--<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/plain;charset=UTF-8</value></list></property>-->
            <!--</bean>-->
        <!--</list>-->
    <!--</property>-->
<!--</bean>-->      

这个虽然是解决了返回集合,但是前端接收的值,有点怪,所以我还是比较喜欢返回字符串(可以把集合转换为字符串来着)

继续阅读