2016-05-27 79 views
0

無法獲取列表進入從Spring MVC的Ajax響應得到406(不接受),但能夠得到的字符串,在這裏我的代碼無法從Spring MVC中獲取列表爲Ajax響應

@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> 

有無嘗試了很多東西像地圖,JSON等,但得到相同的,任何幫助將是appre ciate。

+0

有什麼錯誤? –

+0

@MadPhysicist 406(Not Acceptable)在瀏覽器控制檯上...! –

+0

你能發佈你的spring mvc配置嗎? – codependent

回答

1

以下豆添加到您的配置:

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

什麼是id =「jacksonConverter」,它在哪裏使用? –

+0

拋出java.lang.ClassNotFoundException:com.fasterxml.jackson.core.JsonProcessingException, –

+0

我添加了一些罐子也.. –