三级联动

阅读更多
 

 

1、页面信息

 

#if($!showSwitch == "testFirst")
		                        
*
*
#end

 

2、ajax

 

//当【部门】变化时,设置与之对应的所有的【系统】的值
		function setSystem(){
			var deptCode = $("#projectDept").val();
			
			$.ajax({
			     type :'get',
			     url: "${appRoot}/system/getSystemAjax.do?deptCode="+deptCode,
			     async:false,
			     dataType: 'json',
			     success: function (packJson) {
			         $("#system").empty();
			         $("#component").empty();
			         $("#componentUser").val("");
			         $('').appendTo($("#system"));
			         if(packJson.length == 0){
			        	 $("#showSystemMessage").show();
			         }else{
			        	 $("#showSystemMessage").hide();
			         }
			         for(var i = 0; i < packJson.length; i++){
						$('').appendTo($("#system"));
			        }
				 }
			});
		}
		
		//当【系统】变化时,设置所有的、对应的 【应用】
		function setComponent(){
			var systemId = $("#system").val();
			$.ajax({
			     type :'get',
			     url: "${appRoot}/component/getComponentAjax.do?systemId="+systemId,
			     async:false,
			     dataType: 'json',
			     success: function (packJson) {
			         $("#component").empty();
			         $("#componentUser").val("");
			         $('').appendTo($("#component"));
			         if(packJson.length == 0){
			        	 $("#showComponentMessage").show();
			         }else{
			        	 $("#showComponentMessage").hide();
			         }
			         for(var i = 0; i < packJson.length; i++){
			        	 $('').appendTo($("#component"));
			        }
				 }
			});
		}
	
		//当【应用】变化时,设置对应的【应用负责人】  //要求:appName唯一
		function setComponentUser(){
			var appName = $("#component").val();
			$.ajax({
			     type :'get',
			     url: "${appRoot}/component/getComponentUserByAppName.do?appName="+appName,
			     async:false,
			     dataType: 'text',
			     success: function (data) {
			    	 $("#componentUser").val("");
			    	 $("#componentUser").val(data);
				 }
			});
		}
		

 

3、Controller

 

@RequestMapping(value = "/system/getSystemAjax.do",method = RequestMethod.GET)
	public void getSystemsByDeptCode(String deptCode,Model model,HttpServletResponse response) throws IOException{
		if (logger.isInfoEnabled()) {
			logger.info("getSystemsByDeptCode(Model model=" + model + ",String deptCode="+deptCode+") -  start ");
		}
		response.setContentType("application/json;charset=UTF-8"); 
		response.setCharacterEncoding("UTF-8"); 
		PrintWriter out = response.getWriter();
		if(deptCode.equals("0009") || deptCode.equals("0010")){
			deptCode = "0004";
		}
		List lists = onlineSystemBiz.findSystemsByDeptCode(deptCode);
		String responseStr = "[";
		boolean first = true;
		for(PmpOnlineSystem line:lists){
			if(first){
				first = false;
			} else {
				responseStr += ",";
			}
			responseStr += "{\"id\":\"" + line.getId() + "\","+"\"system\":\""+line.getSystem()+"\","+"\"system_id\":\""+line.getSystemId()+"\"}";
		}
		responseStr += "]";
		out.write(responseStr);
		
		if (logger.isInfoEnabled()) {
			logger.info("getComponentsBySystemId(Model model=" + model
					+ ") -  end  - return value=line_create");
		}
	}

 

 

@RequestMapping(value = "/component/getComponentAjax.do",method = RequestMethod.GET)
	public void getComponentsBySystemId(Integer systemId,Model model,HttpServletResponse response) throws IOException{
		if (logger.isInfoEnabled()) {
			logger.info("getComponentsBySystemId(Model model=" + model +",Integer systemId="+systemId+ 
					", HttpServletResponse response="+response+") -  start ");
		}
		response.setContentType("application/json;charset=UTF-8"); 
		response.setCharacterEncoding("UTF-8"); 
		PrintWriter out = response.getWriter();
		
		List lists = systemAppBiz.findComponentsBySystemId(systemId);
		String responseStr = "[";
		boolean first = true;
		for(PmpSystemApp line:lists){
			if(first){
				first = false;
			} else {
				responseStr += ",";
			}
			responseStr += "{\"appName\":\"" + line.getAppName() + "\","+"\"componentUser\":\""+line.getAppPerson()+"\","+"\"appId\":\"" + line.getAppId()+"\"}";
		}
		responseStr += "]";
		out.write(responseStr);
		
		if (logger.isInfoEnabled()) {
			logger.info("getComponentsBySystemId(Model model=" + model +",Integer systemId="+systemId+ 
					", HttpServletResponse response="+response+") -  end ");
		}
	}
	

 

 

@RequestMapping(value = "/component/getComponentUserByAppName.do",method = RequestMethod.GET)
	public void getComponentUserByAppName(String appName,Model model,HttpServletResponse response) throws IOException{
		if (logger.isInfoEnabled()) {
			logger.info("getComponentUserByAppName(Model model=" + model + ",String appName="+appName+
					",HttpServletResponse response="+response+") -  start ");
		}
		response.setContentType("application/json;charset=UTF-8"); 
		response.setCharacterEncoding("UTF-8"); 
		PrintWriter out = response.getWriter();
		
		String compUser = systemAppBiz.findComponentUserByAppName(appName);
		if(compUser!=null){
			out.write(compUser);
		}else{
			out.write("");
		}
		
		if (logger.isInfoEnabled()) {
			logger.info("getComponentUserByAppName(Model model=" + model + ",String appName="+appName+
					",HttpServletResponse response="+response+") -  end ");
		}
	}

 

 

 

你可能感兴趣的:(三级联动)