【发布时间】:2016-05-27 07:18:14
【问题描述】:
无法从 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 等,但都得到了相同的结果,任何帮助都将不胜感激。
【问题讨论】:
-
@MadPhysicist 406 (Not Acceptable) on browser console...!
-
你能发布你的 spring mvc 配置吗?
-
@codependent 请检查我更新的问题。
-
这只是配置的开始...
-
@codependent 请检查更新的 xml...!
标签: javascript jquery ajax spring spring-mvc