简单易懂,如何将后台获取的数据显示到页面上

// 1,通过ajax查询
function query() {
  var applyNo = $("#applyNo").val();//获取页面的查询条件
  var entName = $("#entName").val();
  var formName = $("#formName").val();
  var socialCode = $("#socialCode").val();
  var certNo = $("#certNo").val();
  var beginTime = $("#beginTime").val();
  var endTime = $("#endTime").val();
  /*if(beginTime !=null || beginTime !=""){
    beginTime = beginTime.replace(/-/g,'');//替换所有-
  }
  if(endTime !=null || endTime !="") {
    endTime = endTime.replace(/-/g,'');
  }*/
  var requestUrl = context + "/service/bizapply/queryInfo";
//  var requestUrl = context + "/service/bizapply/queryInfo/" + entName + "/"+ formName;
  $.ajax({
    type : "post",
    dataType : "json",
    data : {
      "applyNo" : applyNo,
      "entName" : entName,
      "formName" : formName,
      "socialCode" : socialCode,
      "certNo" : certNo,
      "beginTime" : beginTime,
      "endTime" : endTime,
      },
    url : requestUrl,
    success : function(Json) {//Json为后台model里传过来的数组
      var obj = eval(Json.data);//注意,list里可能不是个单纯数组,因此需要取data
      $("#dataList tbody").html("");//先清空表,再将查询的数据拼接上去
      for (var i=0;i= 10) {
          submitTime += mon + "-";
        }else {
          submitTime += "0" + mon + "-";
        }
        if(day >= 10) {
          submitTime += day;
        }else {
          submitTime += "0" + day;
        }
        submitTime +=" ";
        if(h >= 10) {
          submitTime += h + ":";
        }else {
          submitTime += "0" + h + ":";
        }
        if(m >= 10) {
          submitTime += m;
        }else {
          submitTime += "0" + m;
        }
        
        var $tr = $("");
        $tr.append(""+(i+1)+"");
        $tr.append(""+obj[i].APPLY_NO+"");
        $tr.append(""+obj[i].ENT_NAME+"");
        $tr.append(""+obj[i].SOCIAL_CODE+"");
        $tr.append(""+obj[i].FORM_NAME+"");
        $tr.append(""+obj[i].FORM_ID+"");
//        $tr.append(""+year+"-"+mon+"-"+day+" "+h+":"+m+"");
        $tr.append(""+submitTime+"");
        $tr.append(""+obj[i].CERT_NO+"");
        $("#dataList tbody").append($tr);
      }
    },error: function () {
        alert("加载失败");
    }
  });
}
//后台写法,此处只返回model
    @RequestMapping(value = "/queryInfo", method = RequestMethod.POST)

    @ResponseBody
    public Map queryInfo(String entName, String formName, String socialCode, String certNo,
            String applyNo, String beginTime, String endTime, HttpServletRequest request) {
        Map model = new HashMap();
        List> data = applyService.complexQuery(entName, formName, socialCode, certNo, applyNo,
                beginTime, endTime);
        model.put("data", data);
        model.put("total", data.size());
        return model;
    }

// 2,通过form查询
function query() {
  var applyNo = $("input[name='applyNo']").val();
  var entName = $("input[name='entName']").val();
  var socialCode = $("input[name='socialCode']").val();
  var formName = $("input[name='formName']").val();
  var certNo = $("input[name='certNo']").val();
  var beginTime = $("input[name='beginTime']").val();
  var endTime = $("input[name='endTime']").val();
  queryFormId.action = context + "/service/bizapply/queryInfo";
  queryFormId.method = "POST";
  queryFormId.submit();
}
//form查询Jsp页面详细写法
 
//后台写法,注意queryData,这是条件回显,后台变为了返回modelAndView,页面会刷新,虽然查询显示出来了数据,但是输入的查询条件会不存在,因此后台方法需要变化 @RequestMapping(value = "/queryInfo",method = RequestMethod.POST) @ResponseBody public ModelAndView queryInfo(@RequestParam Map map, HttpServletRequest request) { String entName = (String) map.get("entName"); String formName = (String) map.get("formName"); String socialCode = (String) map.get("socialCode"); String certNo = (String) map.get("certNo"); String applyNo = (String) map.get("applyNo"); String beginTime = (String) map.get("beginTime"); String endTime = (String) map.get("endTime"); Map model = new HashMap(); model.put("message", "欢迎进入查询页面"); List> data = applyService.complexQuery(entName, formName, socialCode, certNo, applyNo, beginTime, endTime); Map queryData = new HashMap(); queryData.put("entName",entName); queryData.put("formName",formName); queryData.put("socialCode",socialCode); queryData.put("certNo",certNo); queryData.put("applyNo",applyNo); queryData.put("beginTime",beginTime); queryData.put("endTime",endTime); model.put("queryData",queryData); model.put("data",data); return new ModelAndView("/bizapply/apply/query/complex_query",model); }

 

你可能感兴趣的:(JS)

网上申请号: