Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring MVC:无法以JSON格式提交表单数据_Spring_Spring Mvc - Fatal编程技术网

Spring MVC:无法以JSON格式提交表单数据

Spring MVC:无法以JSON格式提交表单数据,spring,spring-mvc,Spring,Spring Mvc,执行此操作时获取以下异常 HandlerMethod details: Controller [application.entry.controller.UserController] Method [public java.lang.String application.entry.controller.UserController.handleSave(java.util.List<java.util.Map<java.lang.String, java.lang.String

执行此操作时获取以下异常

HandlerMethod details: 
Controller [application.entry.controller.UserController]
Method [public java.lang.String application.entry.controller.UserController.handleSave(java.util.List<java.util.Map<java.lang.String, java.lang.String>>)]

org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/x-www-form-urlencoded' not supported
    at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters(AbstractMessageConverterMethodArgumentResolver.java:124)[org.springframework.web.servlet-3.1.1.RELEASE.jar:3.1.1.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters(AbstractMessageConverterMethodArgumentResolver.java:91)[org.springframework.web.servlet-3.1.1.RELEASE.jar:3.1.1.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:71)[org.springframework.web.servlet-3.1.1.RELEASE.jar:3.1.1.RELEASE]
jQuery提交:

@RequestMapping(value="/save", method=RequestMethod.POST)
@ResponseBody public String handleSave(@RequestBody List<Map<String, String>> client)
    {
        Map<String, String> formInputs = new HashMap<String, String>();

        for (Map<String, String> formInput : client) {
            formInputs.put(formInput.get("name"), formInput.get("value"));
        }
$('form').submit(function () {
                    alert();
                    $.ajax({
                        url: $(this).attr('action'),
                        type: 'POST',
                        data: JSON.stringify($(this).serializeArray()),
                        contentType: 'application/json',
                        success: function (data) {
                            alert('data')
                        },
                        error: function (jqXHR, textStatus, errorThrown) {
                            alert('An error has occured!! :-(')
                        }
                    })

                    return false
                })

尝试调整
@RequestMapping
以接受JSON

@RequestMapping(
    value="/save", 
    method=RequestMethod.POST, 
    consumes="application/json")
原始错误说明“内容类型”应用程序/x-www-form-urlencoded“不受支持”。为什么添加consumes=“application/json”会解决这个问题?
@RequestMapping(
    value="/save", 
    method=RequestMethod.POST, 
    consumes="application/json")