前端关键代码如下:
需要传到后台的对象
user:{
roomId:'',
peopleIdentity:'',
name:'',
pushMoney:0.0
}
ajax请求
KF2(){
let _this=this;
alert(this.user.peopleIdentity)
axios({
url:"/addKF",
methods:"post",
params: {
user:_this.user
}
}).then(resp=>{
var i= resp.data.addKF;
alert(i);
if (i>0){
alert("开房成功");
}
})
}
controller层数据如下:
@PostMapping("/addKF")
public String addKF(@RequestBody User user, HttpServletResponse response)throws Exception{
System.out.println("我进来开房的controller");
System.out.println(user);
int i = hotelService.addKF(user);
System.out.println("添加的状态为:"+i);
JSONObject jsonObject=new JSONObject();
jsonObject.put("addKF",i);
PrintWriter writer = response.getWriter();
writer.print(jsonObject);
return null;
}