嗨我想添加一個參數到ajax請求並將其發送回控制器。如何將參數從ajax傳遞到彈簧mvc控制器
你能幫我解決這個問題嗎?我不明白爲什麼在控制器中我得到了startDate/stopDate參數的空值。
感謝
function getFilterParams() {
return {
"type" : "GET",
"url" : "results",
"async" : true,
"data" : {
"startDate" : $('#startDatePicker').find("input").val(),
"stopDate" : $('#stopDatePicker').find("input").val(),
success : function() {
alert("success ");
},
error : function() {
alert("error");
}
}
};
}
@RequestMapping(value = "/results", method = RequestMethod.GET)
public @ResponseBody DatatablesResponse<Results> findAllForDataTables(HttpServletRequest request) {
System.out.println(request.getParameter("startDate")); // This shows nothing
DatatablesCriterias dataTableCriterias = DatatablesCriterias.getFromRequest(request);
// Add the extra parameters into the DatatablesCriterias object to facilitate filtering
for (ColumnDef columnDef : dataTableCriterias.getColumnDefs()) {
switch (columnDef.getName()) {
case "startDate":
columnDef.setSearch(request.getParameter("startDate"));
break;
case "stopDate":
columnDef.setSearch(request.getParameter("stopDate"));
break;
}
}
DataSet<Results> results = this.resultsServiceimpl.findResultsWithDatatablesCriterias(dataTableCriterias);
return DatatablesResponse.build(results, dataTableCriterias);
}
添加實際發送到服務器的參數'startDate'和'stopDate' –