ajax請求傳參數復雜對象list,后端springmvc接收參數


也是同樣的問題, 浪費我不少時間,在此記錄

問題描述:

  ajax請求后端,springmvc接收參數, 參數是個對象,屬性中有list

解決方法:

JS:

function save() {
  var gifts = [];
  var rows = detail.fnGetNodes();
  for (var i = 0; i < rows.length; i++) {
    var gift = {};
    var row = detail.fnGetData(rows[i]);
    gift['scode'] = row.scode;
    gift['smarkertValue'] = row.smarkertValue;
    gift['cpCount'] = count ? 1 : count;
    gifts.push(gift);
  }
 
  var params= {};// 參數對象
  params.templateName = $('#_tName').val();
  params.templateCode = $('#templateCode').val();
  params.infos = gifts;
  // 發送ajax
$.ajax({
  url:"/autoinsur/template/create.json",
  type : "POST",
  dataType:"json",
  async: false,
  contentType : 'application/json;charset=utf-8',
  data : JSON.stringify(params),
  success: function (data) {
    if (data.resultCode != '0') {
      $.dopAlert("操作失敗: " + data.resultMsg);
    }
  },
  error: function () {
    $.dopAlert("系統繁忙,請稍后重試");
  }
 });
}
 
后端controller代碼:
@RequestMapping("/template/create.json")
@ResponseBody
public CommonResult create(@RequestBody AIGiftTemplateQueryDto dto) {
  return null;
}
 
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM