avalon前端js直接通过ajax请求传一个对象到后台
代码如下:
//企业开票信息
vm.invoiceInfo = {
companyId : "", //企业Id
companyName : "", //企业名称
companyAddress : "", //公司地址
companyTelphone : "", //公司电话
fax : "", //公司传真
contactName : "", //联系人
usdBank : "", //美金开户银行
usdBankNumber : "", //美金开户银行账号usdBankNumber
cnyBank : "", //人民币开户银行
cnyBankNumber : "", //人民币开户银行账号
taxCode : "", //纳税人识别号
taxTypes : "", //纳税类型
receiver : "", //收件人
receiverContactType : "", //联系方式
receiverCompanyName : "", //公司名称
sendAddressCode : "", //省市区地址的code值
sendAddress :"", //省市区
regionAddress : "", //收件详细地址
requirement : "" //开票要求
}
var data = voiceVm.invoiceInfo.$model;
avalon.ajax({
url : "/dzg-system-rest/rest/invoice/save",
type : "post",
dataType : "json",
data : data,
success : function(data){
if (data == 1){
vm.message = "保存成功!";
dialogVm.toggle = true;
voiceVm.taxTpyesFlag = true;
voiceVm.getVoiceInfo();
}else{
vm.message = "保存失败!";
dialogVm.toggle = true;
}
}
});
后台用一个对象去接收:
@ResponseBody
@RequestMapping(value = "/save",method={RequestMethod.GET,RequestMethod.POST})
public int savaInvoice(InvoiceAddressInfo info) {
IInvoiceAddressInfoService invoiceAddressInfoService;
int flag=0;
try {
Long companyId = IdentityHelper.getOrgId();
PHPRPCClientService invoiceService = SpringContextHolder.getBean("invoiceService");
invoiceAddressInfoService = invoiceService.getPHPRPCService(IInvoiceAddressInfoService.class);
if (null==invoiceAddressInfoService.selectInvoiceInfoByCompanyId(companyId)) {
flag = invoiceAddressInfoService.insertInvoiceInfo(info);
}else{
flag = invoiceAddressInfoService.updateInvocieInfo(info);
}
} catch (Exception e) {
logger.error("", e);
}
return flag;
}