简体   繁体   English

@RequestMapping 处理特殊字符

[英]@RequestMapping handling of special characters

I have a REST API我有一个 REST API

@RequestMapping(value = "/Save", method = RequestMethod.POST, 
            consumes = {"application/json;charset=ISO-8859-1" }, 
            produces = {"application/json;charset=ISO-8859-1" })    
public SaveResponse save(@RequestBody SaveRequest request) {
        //some codes
    }
}

My request contains the following lines我的请求包含以下几行

{
  :
  :
      "mailingAddress": {
      "addressLine1": "Carrera 36E N°",
      "addressLine2": "Medellín, Antioquia",
      "country": "COL"
    }
  :

And I received a 400 Bad Request我收到了一个 400 错误的请求

HTTP/1.1 400 Bad Request
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Date: Wed, 16 Jun 2021 12:26:37 GMT
Pragma: no-cache
Content-Length: 0
Expires: 0
X-Frame-Options: DENY
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
X-RBT-Optimized-By: CANA014IJT (RiOS 6.1.1a #11) SC

And when I removed the characters "°" and "í" from the request, then the request can go through with no error.当我从请求中删除字符“°”和“í”时,请求可以顺利通过。 What is my problem?我的问题是什么?

Thank you.谢谢你。

您可以尝试将字符集从 ISO-8859-1 更改为 UTF-8,因为前者不支持如此宽的字符映射数组( UTF-8 和 ISO-8859-1 之间有什么区别? )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM