解决方案 »

  1.   

    经过一番排查,发现是没有配置相应的HttpMessageConverter,在springmvc的配置文件中加入<mvc:annotation-driven/>后,不再报415,而是报400 Bad Request,后台有错误信息:2015-01-07 11:26:29,502 [qtp1683698824-28] DEBUG [org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor] - Reading [java.util.List<org.xu.domain.Book>] as "application/json;charset=UTF-8" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@749297a4]
     2015-01-07 11:26:29,572 [qtp1683698824-28] DEBUG [org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver] - Resolving exception from handler [public void org.xu.web.BookController.updateBook(java.util.List<org.xu.domain.Book>)]: org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token
     at [Source: org.eclipse.jetty.server.HttpInput@92fba00; line: 1, column: 1]; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token
     at [Source: org.eclipse.jetty.server.HttpInput@92fba00; line: 1, column: 1]
     2015-01-07 11:26:29,572 [qtp1683698824-28] DEBUG [org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver] - Resolving exception from handler [public void org.xu.web.BookController.updateBook(java.util.List<org.xu.domain.Book>)]: org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token
     at [Source: org.eclipse.jetty.server.HttpInput@92fba00; line: 1, column: 1]; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token
     at [Source: org.eclipse.jetty.server.HttpInput@92fba00; line: 1, column: 1]
     2015-01-07 11:26:29,572 [qtp1683698824-28] DEBUG [org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver] - Resolving exception from handler [public void org.xu.web.BookController.updateBook(java.util.List<org.xu.domain.Book>)]: org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token
     at [Source: org.eclipse.jetty.server.HttpInput@92fba00; line: 1, column: 1]; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token
     at [Source: org.eclipse.jetty.server.HttpInput@92fba00; line: 1, column: 1]
      

  2.   

    解决啦:①springMVC中加入<mvc:annotation-driven/>
    ②controller中改public void updateBook(@RequestBody List<Book> books) {}为public void updateBook(@RequestBody Book[] books) {}
    ③store中writer : {
                        //encode : true,
                        type: 'json',
                        allowSingle : 'true'
                        //root: 'data'
                    }, 改为writer : {
                        //encode : true,
                        type: 'json',
                        allowSingle : false
                        //root: 'data'
                    },