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;
}