我的代码就像:
@Controller
@RequestMapping( value = "/walley/login", method = RequestMethod.POST)
public void login(HttpServletRequest request,
HttpServletResponse response,
@RequestBody RequestDTO requestDTO)
throws IOException, ServiceException {
String userName = requestDTO.getUserName();
String password = requestDTO.getPassword();
System.out.println("userName " + userName +" :: password "+ password);}
RequestDTO.java文件
public class RequestDTO {
public String userName;
public String password;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
使用postman中的以下步骤点击发布请求。
作为回应我收到错误:
org.springframework.web.HttpMediaTypeNotSupportedException:Content type 'application/json' not supported
我检查过,我在Spring 3.1.X或3.2.X中找到了我们可以在@RequestMapping中设置内容类型“使用者和生产者”以获取请求并且它有效但在3.0.2中它们不支持“消费者和生产者”。那么如何使用@RequestBody注释在Spring 3.0.2版本中设置请求内容类型呢?
答案 0 :(得分:2)
我们没有Spring版本3.0.2的“使用者和生产者”,因此我们需要在root pom.xml和dispatch-servlet.xml中添加一些额外的条目以使用@RequestBody注释。
的pom.xml
$array = array('item1','item2','item3','item4','item5','item6','item7','item8','item9','item10');
$i = 1;
$j = 1;
echo $div = '<div class="group'.$j.'">';
foreach ($array as $value) {
if($i==1){
echo $value.'<br/>';
echo '</div>';
}elseif($i%4==2){
$j++;
echo '</div>
<div class="group'.$j.'">';
echo $value.'<br/>';
}else{
echo $value.'<br/>';
}
$i++;
}
调度-servlet.xml中
<!-- jackson -->
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.13</version>
</dependency>
应该喜欢控制器
<bean id="jacksonMessageConverter"
class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"></bean>
<bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<list>
<ref bean="jacksonMessageConverter" />
</list>
</property>
</bean>