ajax向后端传输pojo对象400错误
1、前端代码
sms对象:
var sms = {
taskId: '',
taskTypeId : '',
schemaId : '',
destPhones : [],
// destPhones.push("+86" + $("#callPhone").val());
contractId : '', // 合同编号
custName : '', //客户姓名
bankName : '',// 银行
accountNo : '',// 账号
overdueAmount : '', //逾期金额
carLoanAmount : '', //车贷逾期
extensionAmount : '', //延保逾期
insuranceAmount : '', //保险逾期
maintainAmount : '',//保养逾期
addedValueAmount : '',//增值额逾期
}
ajax请求:
function sendSms(sms, target, pt) {
$.ajax({
dataType : "json",
type : "POST",
contentType:'application/json;charset=UTF-8',
url : contextPath + "/inbound/sendSmsTreansfer.json",
data : JSON.stringify(sms),
timeout : 30000,
error : function handleAjaxError(xhr, textStatus, error) {
if (textStatus === "timeout") {
$.Alert("连接超时!请稍后再试");
} else if (textStatus == "error") {
$.Alert("系统繁忙,请稍后再试", null);
} else {
$.Alert("系统异常,请联系管理员!");
}
},
beforeSend : function() {
$.showPopupLayer();
},
complete : function() {
$.closePopupLayer();
},
success : function(data) {
if(data) {
if(data.rtnCode == 101) {
$.Alert("短信发送失败!");
} else if(data.rtnCode == 102) {
resendCountDown(target, pt + sms.schemaId + sms.destPhones[0].val(), parseInt(data.errMsg));
} else {
resendCountDown(target, pt + sms.schemaId + sms.destPhones[0].val(), 60);
}
}
}
});
}
2、后端代码
@RequestMapping(value = "/sendSmsTreansfer" ,method = RequestMethod.POST)
public String testTransfer(@RequestBody final SmsDiyVo sms,HttpSession session, Model model){
System.out.println(1);
return new String("redirect:/inbound/sendMessageDiyView.htm");
}
3、原因:SmsDiyVo pojo对象里面没有构造方法、setter、getter
4、解决方法:在pojo对象里添加构造方法和stter、getter