Org. springframework. web. HttpMediaTypeNotSupportedException: Content type 'application/json; charset = UTF-8 'not supported or other Content type does not support processing, contenttypecharset
The framework was not built from start to end for a long time. During the setup process today, the springmvc controller method always prompts various not supported parameters when @ RequestBody is used to automatically bind parameters.
There are two solutions for troubleshooting:
1) when submitting using the post protocol, check the Content type, for example:
$. Ajax ({type: "POST", contentType: "application/json; charset = UTF-8", url: "/reg", data: JSON. stringify (data. field), dataType: 'json', success: function (result) {if (result. code = 0) {layer. msg ('registration successful! ') ;}Else {layer. msg (result. msg );}}});
Check the contentType Type above. If you want to use the springmvc @ RequestBody annotation to submit the json string automatically bound to the pojo input parameter, the type must be "application/json; charset = UTF-8 ", otherwise, an "not supported" exception is thrown.
2) The jackson-databind jar package is missing.
Add the coordinates of maven or gradle as follows:
Maven:
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind --><dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.8.8.1</version></dependency>
Gradle:
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.8.8.1'
Then the controller can be used directly like this:
@ RequestMapping (value = "/reg", method = RequestMethod. POST) @ ResponseBody public ResponseVo reg (@ RequestBody user u) throws Exception {// other crud logic}