簡體   English   中英

無法將列表從Spring MVC轉換為Ajax響應

[英]Unable to get List into ajax response from Spring MVC

無法將列表從Spring MVC的Ajax響應中獲取406(不可接受),但能夠獲取字符串,這里是我的代碼

@ResponseStatus(value = HttpStatus.OK)
@RequestMapping(value = "/getCategory", method = RequestMethod.POST, headers = "Accept=*/*", produces = "application/json")
public @ResponseBody List<Info> initCategory(@ModelAttribute(value = "getCategories") Info info) {
    List<Info> category = null;
    try {
        category = infoService.getCategory(info.getPlantName());
    } catch (NullPointerException e) {
        e.printStackTrace();
    }
    return category;
}

阿賈克斯

    function selectCategory() {
        var plantId = $('#plantId').val();
        alert(plantId);
        $.ajax({
                    url : '/veQNL/addPro/getCategory',
                    type : 'POST',
                    data : $("#addProject").serialize(),
                    success : function(result) {
                        alert(result);
                    }
        });
}

和調度員

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
 http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
 http://www.springframework.org/schema/context
 http://www.springframework.org/schema/context/spring-context-4.0.xsd
 http://www.springframework.org/schema/mvc 
 http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
<!--registration and scanning all controller ,service ,repository annotation -->
<context:component-scan base-package="com.ve.qnl" />
<!-- jdbc resource -->

<context:property-placeholder location="classpath:resources/database.properties" />
<bean id="jspViewResolver"
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="viewClass"
        value="org.springframework.web.servlet.view.JstlView" />
    <property name="prefix" value="/WEB-INF/views/" />
    <property name="suffix" value=".jsp" />
</bean>
<bean id="dataSource"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="${database.driver}" />
    <property name="url" value="${database.url}" />
    <property name="username" value="${database.user}" />
    <property name="password" value="${database.password}" />
</bean>

<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
    <property name="dataSource" ref="dataSource" />
</bean>
<mvc:resources mapping="/resources/**" location="/resources/"
    cache-period="31556926" />
<mvc:annotation-driven /></beans>

嘗試過很多東西,例如Map,Json等,但是得到相同的幫助,將不勝感激。

將以下bean添加到您的配置中:

<bean id="jacksonConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" />

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM