Org. springframework. web. HttpMediaTypeNotSupportedException: Content type & #39; application/json; charset = UTF-8 & #39; not supported or other Content type does not support processing, contenttypecharset

Source: Internet
Author: User

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}

 



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.