欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

ssm后端传json字符串到前端出现问号乱码的情况

程序员文章站 2022-06-23 08:29:32
ssm后端传json字符串到前端出现问号乱码的情况解决方案一(网上推荐的,我没试过)在@RequestMapping中添加produces = {“application/json;charset=UTF-8”} @RequestMapping(value="abc",produces = {"application/json;charset=UTF-8"})解决方案二因为我用的是ResponseEntity,所以我直接在返回头请求中将Content-Type设置成application/jso...

ssm后端传json字符串到前端出现问号乱码的情况

解决方案一(网上推荐的,我没试过)

在@RequestMapping中添加produces = {“application/json;charset=UTF-8”}

 @RequestMapping(value="abc",produces = {"application/json;charset=UTF-8"})

解决方案二

因为我用的是ResponseEntity,所以我直接在返回头请求中将Content-Type设置成application/json;charset=UTF-8

@RequestMapping(value = "/login", method = RequestMethod.POST)
    public ResponseEntity<String> login(@RequestBody Map info){
        
        // todo 新建头请求 在这里设置
        MultiValueMap<String, String> header = new HttpHeaders();
        header.set("Content-Type","application/json;charset=UTF-8");
		
        ResponseEntity<String> stringResponseEntity = new ResponseEntity<String>("str",header, HttpStatus.OK);
        return stringResponseEntity;
    }

本文地址:https://blog.csdn.net/weixin_43426254/article/details/109252744