經驗分享之前臺Map數據的顯示

前臺Map數據的顯示:


controller:

//-----------根據稿件Id查詢稿件信息-----------start------------
  @ResponseBody
  @RequiresPermissions("sys:uploadPictorial:edit")
  @RequestMapping(value = "queryManuscriptById")
  public Map<String,Object> queryManuscriptById(@RequestParam Map<String,String> params,HttpServletRequest request,HttpServletResponse response,ManuscriptInfo manuscriptInfo, Model model) {
    String manuscriptId=request.getParameter("manuscriptId");//獲得稿件的id
    String pictorialId = request.getParameter("pictorialId");//獲取期刊的ID
    Map<String,Object> paramMap=new HashMap<String,Object>();
    PictorialInfo pictorialInfo = new  PictorialInfo();
    //從Mongo數據庫中讀取稿件信息
    paramMap.put("id", manuscriptId);
    ManuscriptInfo m=mongoService.findObject(ManuscriptInfo.class,paramMap,null,null,null,null,null,null);
    //獲取期刊的總頁數
    if(!StringUtils.isEmpty(pictorialId)){
      pictorialInfo = uploadpictorialService.get(pictorialId);
    }
    int totalPage = pictorialInfo.getPgNum();
    
    //計算起始頁和結束頁,並將計算出來的數據放入retMap
    Map<String,Object> retMap=new HashMap<String,Object>();
    int startPage = m.getPgStart();
    int stopPage = m.getPgStop();
    String stopPagePos = null;
    if(startPage==1){
      startPage=m.getPgStart();
    }else if(startPage==totalPage){
      startPage=(startPage+2)/2;
    }else{
      if(startPage%2==1){
        startPage=(startPage+1)/2;
      }else if(startPage%2==0){
        startPage=(startPage+2)/2;
      }
    }
    
    if(stopPage==1){
      stopPage=m.getPgStop();
      stopPagePos="L";
    }else if(stopPage==totalPage){
      stopPage=(stopPage+2)/2;
      stopPagePos="R";
    }else{
      if(stopPage%2==1){
        stopPage=(stopPage+1)/2;
        stopPagePos="R";
      }else if(stopPage%2==0){
        stopPage=(stopPage+2)/2;
        stopPagePos="L";
      }
    }
    
    //將所有的數據放入Map
    if(m!=null){
      retMap.putAll(m.getExtraProps());
      retMap.put("title", m.getTitle());
      retMap.put("author", m.getAuthor());
      retMap.put("pg_start", startPage);
      retMap.put("pg_stop", stopPage);
      retMap.put("pg_start_pos", m.getPgStartPos());
      retMap.put("pg_stop_pos", stopPagePos);
      retMap.put("securityLevel", m.getSecurityLevel());
    }
    return retMap;
  }
  //-----------根據稿件Id查詢稿件信息-----------end------------
	

JSP:

/* 顯示錶單頁面 */
		function ShowForm(id){
		  manuId=id.substring(4);
		  //獲取當前期刊的ID
	      var Request = new Object();
	      Request = GetRequest();
	      var pictorialId = Request['pictorialId'];//得到主頁面傳遞過來的pictorialId
		  if(id != "btnNew"){
			  $.ajax({
		            //提交數據的類型 POST GET
		            type:"POST",
		            //提交的網址
		            url:"${ctx}/sys/uploadPictorial/queryManuscriptById",
		            data:{"manuscriptId":manuId,"pictorialId":pictorialId},
		            //返回數據的格式
		            datatype: "text",//"xml", "html", "script", "json", "jsonp", "text".
		            //成功返回之後調用的函數             
		            success:function(res){
		              //alert("稿件信息回顯成功!");
		              for(var key in res){
		            	var textKey = "#"+key;  
		            	$(textKey).val(res[key]);//數據回顯
		              }
		            },
		            error:function(){
			              alert("稿件信息回顯失敗!"); 
			        }
		         }); 
			  $("#formBtns").hide();
			  $("#listBtns").hide();
			  $("#sepManuscript").show();
			  $("#subListForm").hide();
			  $("#editBtns").show();
	      }else{
		      $('#sepManuscript')[0].reset();
		      $("#formBtns").show();
		      $("#listBtns").hide();
		      $("#sepManuscript").show();
		      $("#subListForm").hide();
		      $("#editBtns").hide();
			  }
		}




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章