VS Code+SpringBoot请求入参乱码解决

521 阅读1分钟

1.windows 环境下,VS Code编译器默认字符集为UTF-8,但是本地测试发现,中文入参传到后端接口仍乱码

image.png

2.点击运行和调试,打开launch.json配置文件,默认没有配置项encoding,需要手动添加

image.png

launch.json

image.png

3.重启项目再次访问接口,乱码解决了

image.png

补充:如果VS Code控制台乱码,需要在settings.json配置中添加如下配置即可解决

"terminal.integrated.profiles.windows": {
    "PowerShell": {
        "source": "PowerShell",
        "icon": "terminal-powershell",
        "args": [
            "-NoLogo",
            "-NoExit",
            "-Command",
            "chcp.com 65001"
        ]
    },
    "Command Prompt": {
        "path": [
            "${env:windir}\\Sysnative\\cmd.exe",
            "${env:windir}\\System32\\cmd.exe"
        ],
        "args": [
            "/K",
            "chcp 65001"
        ],
        "icon": "terminal-cmd"
    }
}