入口函数的定义为:
@At("/jsonAdapter")
@Ok("json")
@AdaptBy(type=JsonAdaptor.class)
public Friend jsonAdapterTest(Friend friend){
return friend;
}
实体类Friend的定义为:
public class Friend {
private int id;
private String name;
private int age;
private String sex;
private String relation;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getRelation() {
return relation;
}
public void setRelation(String relation) {
this.relation = relation;
}
@Override
public String toString() {
return "Friend [id=" + id + ", name=" + name + ", age=" + age + ", sex=" + sex + ", relation=" + relation + "]";
}
}
前端ajax代码为:
<body>
<input type="button" onclick="send1()" value="发送一个friend的json数据包"/>
</body>
<script type="text/javascript">
function send1(){
var data = {id:1,name:'陆离',age:19,sex:'女',relation:'媳妇'};
$.ajax({
url:'/HelloNutz/jsonAdapter',
data:data,
dataType:'json',
success:function(data){
console.log(data);
}
});
}
</script>
问题为: 断点到入口函数,friend参数为null,甚是不解,求解答。