码迷,mamicode.com
首页 > 编程语言 > 详细

springMVC返回json数据乱码问

时间:2019-06-29 11:16:30      阅读:112      评论:0      收藏:0      [点我收藏+]

标签:返回   val   sts   turn   ret   sonar   produce   string   简单的   

在springMVC controller中返回json数据出现乱码问题,因为没有进行编码,只需要简单的注解就可以了

在@RequestMapping()中加入produces="text/html;charset=UTF-8"属性即可,如下:

    @RequestMapping(value="/respost",method=RequestMethod.GET,produces="text/html;charset=UTF-8")
    @ResponseBody
    public String postList(@RequestParam("topicId") String topicId){
        List<Post> posts=new ArrayList<Post>();
        System.out.println("topicId-----"+topicId);
        posts=postService.findPostList(topicId);
        JSONArray postJson=JSONArray.fromObject(posts);
        return postJson.toString();
    }    

 

springMVC返回json数据乱码问

标签:返回   val   sts   turn   ret   sonar   produce   string   简单的   

原文地址:https://www.cnblogs.com/yysbolg/p/11101988.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!