ajax向后台 controller传递参数

function saveReportData(fileName,fileID) {
    console.log("fileName="+fileName);
    $.ajax({
        type : 'post',
        url : '${ctx}/reportmanage/specialReportManage/saveReportData',
        data:{'srFileName':fileName,"srFileID":fileID},
        traditional : true,
        async : false,        
        success : function(result){
            
        },
        error : function(result){
        }
    });    
}

接收方式两种

  •     说明:ajax的data参数名称(红色标识)必须和@RequestParam中的参数名称保持一致
  • @RequestMapping(value = "saveReportData")
  •     @ResponseBody

      public String saveReportData(@RequestParam(value = "srFileName", defaultValue = "") String FileName,
              @RequestParam(value = "srFileID", defaultValue = "") String FileID) throws IOException {
          specialReportManageService.saveReportData(FileName, FileID);
          return "";
        }

  • 说明:如果没有添加@RequestParam,函数的参数名称必须和ajax中的参数名称一致
  • public String saveReportData( String srFileName,String srFileID) throws IOException {

          specialReportManageService.saveReportData(FileName, FileID);
          return "";
        }

原文地址:https://www.cnblogs.com/tsx1230/p/8041683.html