jsp 讀取資料, 封裝成JSON陣列,後臺獲取
阿新 • • 發佈:2018-12-19
jsp:
function saveNames(){ var rows = jQuery('#gzgi_DataGrid').datagrid('getSelections'); if (rows == null || rows.length < 1) { alertGzgi('Info', '請選擇至少1條記錄!', 'info'); } else { var datagrids = []; for(var i=0; i<rows.length; i++){ datagrids.push({"model":rows[i].model,"machineType":rows[i].machineType,"option":rows[i].option,"yearstr":rows[i].yearstr}); } if(datagrids.length != 0){ var params = JSON.stringify(datagrids); var paramsData = { params : params }; jQuery.ajax({ type: "", url: '', data: paramsData, dataType: 'json', ... }); } } }
java:
//獲取json字串
String params = request.getParameter("params");
//轉換資料成 list
List<CarType> carTypes = JSONArray.parseArray(params, CarType.class);