我的控制器:
@ResponseBody @RequestMapping(value="/services/subsubsite", method = RequestMethod.POST, consumes = "application/json")
public void subSubsite(@RequestBody SubSubsiteRequest request)
{
}
我的dispatcher-servlet.xml
<?xml version='1.0' encoding='UTF-8' ?>
<!-- was: <?xml version="1.0" encoding="UTF-8"?> -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
">
<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>
<mvc:annotation-driven/>
<context:annotation-config></context:annotation-config>
<context:component-scan base-package="market"></context:component-scan>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp" />
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/market"/>
<property name="username" value="root"/>
<property name="password" value=""/>
</bean>
</beans>
SubSubsiteRequest类:
public class SubSubsiteRequest {
private int subsiteId;
public int getSubsiteId() {
return subsiteId;
}
public void setSubsiteId(int subsiteId) {
this.subsiteId = subsiteId;
}
}
当我执行以下json请求时,我得到415不支持的媒体错误:
{ "subsiteId" : "123" }
(我的请求在其标题中有“content-type = application / json”和“accept = / ”)。
所以我真的很困惑。我在我的项目中使用gradle。我添加了jackson库以防万一,虽然我认为spring已内置它们。可能导致这种情况的原因是什么?