67,516
社区成员
发帖
与我相关
我的任务
分享
<mvc:annotation-driven validator="validator"/>
@RequestMapping(value="/requestJson")
@ResponseBody
public Clientele requestJson(@RequestBody Clientele c){
return c;
}
$.ajax({
type : 'post',
url : '${pageContext.request.contextPath}/requestJson.action',
dataType : 'json',
contentType : 'application/json;charset=UTF-8',
data:'{"name":"顾客","age":25}',
success : function (data) {
alert(data);
},
});
<!-- 使用 mvc:annotation-driven取代了注解方式的适配器与注解方式的映射器 -->
<mvc:annotation-driven validator="validator">
<mvc:message-converters>
<bean class="org.springframework.http.converter.StringHttpMessageConverter"/>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/>
</mvc:message-converters>
</mvc:annotation-driven>
public class Clientele implements Serializable{
private String name;
private Integer age;
public Clientele(){};
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
};
}