mvc 返回中文字符串乱码,返回集合中含有中文不乱码的问题

    @RequestMapping("/hello")
    public String hello() {
        return "你好";
    }
    @RequestMapping("/hello2")
    public Object hello2() {
        return "你好";
    }
    @RequestMapping("/hello3")
    public Object hello3() {
        List<String> list = new ArrayList<>();
        list.add("你好");
        return list;
    }
    @RequestMapping("/hello4")
    public String hello4() {
        return JSON.toJSONString("你好");
    }

除了hello3均乱码

解决方法:
在类注解上修改

@RequestMapping(value = "/debug",  produces="text/html; charset=UTF-8")
发布了327 篇原创文章 · 获赞 82 · 访问量 89万+

猜你喜欢

转载自blog.csdn.net/kkgbn/article/details/79754409