在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();
    }    

 

相关文章:

  • 2021-09-12
  • 2022-02-08
  • 2021-11-26
  • 2022-12-23
  • 2021-11-28
  • 2021-11-17
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-03-06
  • 2022-12-23
  • 2022-12-23
  • 2021-05-20
  • 2022-01-17
  • 2021-05-04
  • 2021-09-10
相关资源
相似解决方案