LoginController.java:
@Controller @RequestMapping("/user") public class LoginController { @RequestMapping(value="receive", method=RequestMethod.POST, consumes="application/json") @ResponseBody public RegInfo receiveData(@RequestBody RegInfo info){//
System.out.println("come here");
System.out.println(info.getRealname());
return info;
}
}
register.xml:
$("#sub").click(function(){
var m = {
"realname": $("#real_name").val(),
"phonenumber": $("#phone_number").val()
};
$.ajax({
type:"POST",
url:"/demo/user/receive",
data:m,
dataType:"json",
contentType:"application/json; charset=utf-8",
async:false,
success:function(data){
alert("nihao");
},
erroe:function(data){
alert("保存失败 ")
}
})
});
RegInfo.java:
public class RegInfo {
private String realname;
private String phonenumber;
//private boolean sex;
public RegInfo(){
}
public void setRealname(String realname){
this.realname= realname;
}
public String getRealname(){
return realname;
}
public void setPhonenumber(String phonenumber){
this.phonenumber = phonenumber;
}
public String getPhonenumber(){
return phonenumber;
}
demo-servlet.xml:
<!-- 默认的注解映射的支持 -->
<mvc:annotation-driven/>
<context:annotation-config/>
i have imported jackson-annotations-2.1.4.jar、jackson-core-2.1.4.jar、jackson-databind-2.1.4.jar in the lib but i cannot see the print in the console and it point 400 bad request in the chorme.I have tried some ways but it does no effect.
Aucun commentaire:
Enregistrer un commentaire