ExtJS4和Spring MVC3发布错误

时间:2012-02-13 04:54:16

标签: ajax spring spring-mvc extjs

我收到以下错误...

POST http://localhost:8080/mytest/admin/user/delete?_dc=1329102157683 415(不支持的媒体类型)

当EXTJS 4 Grid尝试同步()时,我收到此错误。

    api: {
        read:'admin/user/list',
        create:'admin/user/add',
        update:'admin/user/update',
        destroy:'admin/user/delete'
    },
    reader: {
        type: 'json',
        root: 'users',
        totalProperty: 'totalRecords',
        successProperty: 'success'
    },
    writer: {
        type: 'json',
        writeAllFields: true,
        encode: false//,
        //root: 'user'
    },

..... ......

    this.getUsersStore().remove(this.selectedUser);
    this.getUsersStore().sync();

Spring Controller ..,

        @Controller
        @Scope("request")
        public class UserFormController { 
            private static final long serialVersionUID = 5152065663578866866L;
            private static final Logger log = Logger.getLogger(UserFormController.class);

            @RequestMapping(method = RequestMethod.POST, value = "/admin/user/delete", headers = "Accept=application/json")
            @PreAuthorize("hasAuthority('ROLE_ADMIN')")
            public @ResponseBody
            Map<String, ? extends Object> delete(@RequestBody
            User user) {
                if (log.isTraceEnabled()) {
                    log.trace("Entering method 'delete'");
                }
                Map<String, Object> modelMap = new HashMap<String, Object>();
                List<Object> args = new ArrayList<Object>();
                modelMap.put("success", true);
                return modelMap;
            }

弹簧配置......

            <!-- JSON Converters -->
            <bean id="jsonHttpMessageConverter"
                class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
            </bean>

            <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
                <property name="messageConverters">
                    <list>
                        <ref bean="jsonHttpMessageConverter" />
                    </list>
                </property>
            </bean>

            <!-- uses the Jackson library's ObjectMapper to render the response content 
                as JSON -->
            <bean id="jacksonObjectMapper" class="org.codehaus.jackson.map.ObjectMapper" />

            <bean id="mappingJacksonJsonView"
                class="org.springframework.web.servlet.view.json.MappingJacksonJsonView">
                <property name="objectMapper" ref="jacksonObjectMapper"/>
            </bean>

            <!-- Content Delegate -->
            <bean
                class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
                <property name="mediaTypes">
                    <map>
                        <entry key="html" value="text/html" />
                        <entry key="json" value="application/json" />
                    </map>
                </property>
                <property name="viewResolvers">
                    <list>
                        <ref bean="viewResolver" />
                    </list>
                </property>
                <property name="defaultViews">
                    <list>
                        <ref bean="mappingJacksonJsonView" />
                    </list>
                </property>
                <property name="favorPathExtension" value="false" />
                <property name="favorParameter" value="true" />
                <property name="useNotAcceptableStatusCode" value="true" />     
            </bean>

让我知道,

谢谢,

2 个答案:

答案 0 :(得分:0)

经过调试逐步完成路径中的每个课程......发现杰克逊只是“跳舞”而没有任何异常!它在pojo“User”的一个属性上失败了。它根本无法反序列化包含对象的java.util.Map。奇怪的是它可以将所有事情序列化而没有任何问题!

答案 1 :(得分:0)

杰克逊确实能够对列表的对象进行反序列化,只需要知道它们的类型。
我认为在你的情况下它应该是@RequestBody List<User> users
据我所知,REST代理总是尝试批量操作(这是原因
你总是得到一个对象列表。