Spring RestTemplate Charset UTF-8不起作用

时间:2016-09-22 08:36:46

标签: java spring rest spring-mvc utf-8

我想为Multipart / form-data resttemplate请求设置UTF-8字符集。但它不起作用。我在这里阅读了很多答案,但我在休息服务方面只得到???

我的服务器端RestController。在这里,我只得到问号而不是UTF-8文字:

enter image description here

我的客户端RestTemplate代码。此处的表单文字在UTF-8

中正确显示

enter image description here

PS。当我使用Postman作为Rest Client时,文本显示在UTF-8

2 个答案:

答案 0 :(得分:3)

您是否尝试过编码?

map.add("message",URLEncoder.encode(emailForm.getEmailContent(), "UTF-8"));

答案 1 :(得分:0)

我遇到了这个问题。当我在交换方法中使用 uri 而不是字符串时它解决了。

    const d = [
        { date: "2017-02-01", price: 231 },
        { date: "2017-04-01", price: 453 },
        { date: "2017-16-01", price: 123 }, 

        { date: "2018-01-01", price: 234 },
        { date: "2018-04-01", price: 958 },
        { date: "2018-11-01", price: 163 },
        { date: "2018-11-02", price: 163 },
        { date: "2018-11-03", price: 163 },
        { date: "2018-11-06", price: 163 },
        { date: "2018-11-05", price: 163 },
        { date: "2018-11-07", price: 163 },
        { date: "2018-11-08", price: 163 },
        { date: "2018-11-09", price: 163 },
        { date: "2018-11-00", price: 163 },
        { date: "2018-11-11", price: 163 },
        { date: "2018-11-12", price: 163 },
        { date: "2018-11-13", price: 163 },
        { date: "2018-11-14", price: 163 },
        { date: "2018-11-15", price: 163 },
        { date: "2018-11-16", price: 163 },
        { date: "2018-11-17", price: 163 },

        { date: "2019-03-01", price: 293 },
        { date: "2019-10-01", price: 471 },
        { date: "2020-07-01", price: 881 },
        { date: "2020-09-01", price: 122 }
      ];