關於href 跳轉,傳參數,對象

	**window.location.href ,CSDN不容易這樣直接傳名稱。所有就用了“href 跳轉,傳參數,對象”這個標題。**

1.跳轉
window.location.href進行頁面跳轉

window.location.href = url

2.傳參數:
對應在springmvc 的Controller層中(String year,Stringmonth)接收
@RequestMapping(“exportExcelByQuery”)
@ResponseBody
public void exportExcelByQuery(HttpServletRequest request, HttpServletResponse response, integer year ,integer month)

var year = $("#year").val();
var month = $("#month").val();
window.location.href = "xxx.do?year="+year+'&month='+month

3.傳對象 (excel導出功能)
@RequestMapping(“exportExcelByQuery”)
@ResponseBody
public void exportExcelByQuery(HttpServletRequest request, HttpServletResponse response, PersonSalaryQuery query)
前段控制器中的 PersonSalaryQuery query對應window.location.href 中的query

/*導出excel工資表 請求.do*/
function exportExcelByQuery() {
	var year = $("#year").val();
	var month = $("#month").val();
	var gradeClass = $("#gradeClasses").val();
	var url = "/swj_salary/personSalary/exportExcelByQuery.do";
	if (year == 0) {
		year = null;
	}

	if (month == 0) {
		month = null;
	}

	if (gradeClass == 0) {
		gradeClass = null;
	}
	
	var param = {
		//"personCode" : userName,
		"personCode" : 'hutt',
		"year" : year,
		"month" : month,
		"gradeCode" : gradeClass
	};
	var params = JSON.stringify(param);
	alert(params)
	$('tbody').empty(); // 置空
	
	var query = "";
	for(var key in param){
		if(param[key]){
			query += "&"+key+"="+param[key];
		}
	}
	window.location.href ="/swj_salary/personSalary/exportExcelByQuery.do?query="+query;
	}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章