@ResponseBody返回中文乱码

安稳与你 提交于 2020-02-27 16:25:25

在使用SSM后台项目中,我想要使用一个@ResponseBody返回中文信息,但是我发现了乱码情况。

package com.xjj.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/interface")
public class TestController {
    @RequestMapping("/test")
    @ResponseBody
    public String test(){
        return "你好";
    }
}

在这里插入图片描述
解决方法:

1、修改@RequestMapping中的属性

package com.xjj.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/interface")
public class TestController {
    @RequestMapping(value = "/test", produces = {"text/html;charset=utf-8"})
    @ResponseBody
    public String test(){
        return "你好";
    }
}

在这里插入图片描述

这是目前发现有用的方法,以后收集到其他的会继续补充!

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!