JQuery Easy Ui DataGrid

来源:http://www.cnblogs.com/rancrazy/archive/2016/09/22/5894871.html
-Advertisement-
Play Games

Extend from $.fn.panel.defaults. Override defaults with $.fn.datagrid.defaults. The datagrid displays data in a tabular format and offers rich support ...


Extend from $.fn.panel.defaults. Override defaults with $.fn.datagrid.defaults.

The datagrid displays data in a tabular format and offers rich support to select, sort, group and edit data. The datagrid has been designed to reduce development time and to require no specific knowledge from developers. It is both featherweight and feature-rich. Cell merging, multi-column headers, frozen columns and footers are just a few of its features.

依賴

  • panel
  • resizable
  • linkbutton
  • pagination

用法示例

Create datagrid from an existing table element, defining columns, rows, and data in html.

  1. <table class="easyui-datagrid">
  2. <thead>
  3. <tr>
  4. <th data-options="field:'code'">Code</th
  5. <th data-options="field:'name'">Name</th
  6. <th data-options="field:'price'">Price</th
  7. </tr
  8. </thead
  9. <tbody>
  10. <tr>
  11. <td>001</td<td>name1</td<td>2323</td
  12. </tr
  13. <tr>
  14. <td>002</td<td>name2</td<td>4612</td
  15. </tr
  16. </tbody
  17. </table

Create datagrid via <table> markup. The nested <th> tags define the columns on the table.

  1. <table class="easyui-datagrid" style="width:400px;height:250px"
  2. data-options="url:'datagrid_data.json',fitColumns:true,singleSelect:true">
  3. <thead>
  4. <tr>
  5. <th data-options="field:'code',width:100">Code</th
  6. <th data-options="field:'name',width:100">Name</th
  7. <th data-options="field:'price',width:100,align:'right'">Price</th
  8. </tr
  9. </thead
  10. </table

Create datagrid using javascript is also allowed.

  1. <table id="dg"></table
  1. $('#dg').datagrid({
  2. url:'datagrid_data.json',
  3. columns:[[
  4. {field:'code',title:'Code',width:100},
  5. {field:'name',title:'Name',width:100},
  6. {field:'price',title:'Price',width:100,align:'right'}
  7. ]]
  8. });

Query data with some parameters.

  1. $('#dg').datagrid('load', {
  2. name: 'easyui',
  3. address: 'ho'
  4. });

After changing data to server, refresh the front data.

  1. $('#dg').datagrid('reload'); // reload the current page data

 

表格屬性

The properties extend from panel. below is the added properties for datagrid.

名稱類型描述預設值
columns array The datagrid columns config object, see column properties for more details. undefined
frozenColumns array Same as the columns property, but the these columns will be frozen on left. undefined
fitColumns boolean True to auto expand/contract the size of the columns to fit the grid width and prevent horizontal scrolling. false
resizeHandle string Resizing column position, Available value are: 'left','right','both'. When 'right', users can resize columns by dragging the right edge of column headers, etc.
This property is available since version 1.3.2.
right
autoRowHeight boolean Defines if set the row height based on the contents of that row. Set to false can improve loading performance. true
toolbar array,selector The top toolbar of datagrid panel. Possible values:
1) an array, each tool options are same as linkbutton.
2) a selector that indicate the toolbar.

Define toolbar within a <div> tag:

 

$('#dg').datagrid({
	toolbar: '#tb'
});
<div id="tb">
<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true"/a>
<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-help',plain:true"/a>
</div>

Define toolbar via array:

$('#dg').datagrid({
	toolbar: [{
		iconCls: 'icon-edit',
		handler: function(){alert('edit')}
	},'-',{
		iconCls: 'icon-help',
		handler: function(){alert('help')}
	}]
});
null
striped boolean True to stripe the rows. false
method string The method type to request remote data. post
nowrap boolean True to display data in one line. Set to true can improve loading performance. true
idField string Indicate which field is an identity field. null
url string A URL to request data from remote site. null
data array,object The data to be loaded. This property is available since version 1.3.2.

Code example:

$('#dg').datagrid({
	data: [
		{f1:'value11', f2:'value12'},
		{f1:'value21', f2:'value22'}
	]
});
null
loadMsg string When loading data from remote site, show a prompt message. Processing, please wait …
pagination boolean True to show a pagination toolbar on datagrid bottom. false
rownumbers boolean True to show a row number column. false
singleSelect boolean True to allow selecting only one row. false
checkOnSelect boolean If true, the checkbox is checked/unchecked when the user clicks on a row. If false, the checkbox is only checked/unchecked when the user clicks exactly on the checkbox.
This property is available since version 1.3.
true
selectOnCheck boolean If set to true, clicking a checkbox will always select the row. If false, selecting a row will not check the checkbox.
This property is available since version 1.3.
true
pagePosition string Defines position of the pager bar. Available values are: 'top','bottom','both'.
This property is available since version 1.3.
bottom
pageNumber number When set pagination property, initialize the page number. 1
pageSize number When set pagination property, initialize the page size. 10
pageList array When set pagination property, initialize the page size selecting list. [10,20,30,40,50]
queryParams object When request remote data, sending additional parameters also.

Code example:

$('#dg').datagrid({
	queryParams: {
		name: 'easyui',
		subject: 'datagrid'
	}
});
{}
sortName string Defines which column can be sorted. null
sortOrder string Defines the column sort order, can only be 'asc' or 'desc'. asc
multiSort boolean Defines if to enable multiple column sorting. This property is available since version 1.3.4. false
remoteSort boolean Defines if to sort data from server. true
showHeader boolean Defines if to show row header. true
showFooter boolean Defines if to show row footer. false
scrollbarSize number The scrollbar width(when scrollbar is vertical) or height(when scrollbar is horizontal). 18
rowStyler function Return style such as 'background:red'. The function take two parameter:
rowIndex: the row index, start with 0
rowData: the record corresponding to this row

Code example:

$('#dg').datagrid({
	rowStyler: function(index,row){
		if (row.listprice>80){
			return 'background-color:#6293BB;color:#fff;';
		}
	}
});
 
loader function Defines how to load data from remote server. Return false can abort this action. This function takes following parameters:
param: the parameter object to pass to remote server.
success(data): the callback function that will be called when retrieve data successfully.
error(): the callback function that will be called when failed to retrieve data.
json loader
loadFilter function Return the filtered data to display. The function take one parameter 'data' that indicate the original data. You can change original source data to standard data format. This function must return standard data object that contain 'total' and 'rows' properties.

Code example:

// removing 'd' object from asp.net web service json output
$('#dg').datagrid({
	loadFilter: function(data){
		if (data.d){
			return data.d;
		} else {
			return data;
		}
	}
});
 
editors object Defines the editor when editing a row. predefined editors
view object Defines the view of datagrid. default view

 

列屬性

The DataGrid Columns is an array object, which element is an array too. The element of element array is a config object, which defines every column field.

 

Code example:

  1. columns:[[
  2. {field:'itemid',title:'Item ID',rowspan:2,width:80,sortable:true},
  3. {field:'productid',title:'Product ID',rowspan:2,width:80,sortable:true},
  4. {title:'Item Details',colspan:4}
  5. ],[
  6. {field:'listprice',title:'List Price',width:80,align:'right',sortable:true},
  7. {field:'unitcost',title:'Unit Cost',width:80,align:'right',sortable:true},
  8. {field:'attr1',title:'Attribute',width:100},
  9. {field:'status',title:'Status',width:60}
  10. ]]

 

名稱類型描述預設值
title string The column title text. undefined
field string The column field name. undefined
width number The width of column. If not defined, the width will auto expand to fit its contents. undefined
rowspan number Indicate how many rows a cell should take up. undefined
colspan number Indicate how many columns a cell should take up. undefined
align string Indicate how to align the column data. 'left','right','center' can be used. undefined
halign string Indicate how to align the column header. Possible values are: 'left','right','center'. If not assigned, the header alignment is same as data alignment defined via 'align' property. This property is available since version 1.3.2. undefined
sortable boolean True to allow the column can be sorted. undefined
order string The default sort order, can only be 'asc' or 'desc'. This property is available since version 1.3.2. undefined
resizable boolean True to allow the column can be resized. undefined
fixed boolean True to prevent from adjusting width when 'fitColumns' is set to true. undefined
hidden boolean True to hide the column. undefined
checkbox boolean True to show a checkbox. The checkbox column has fixed width. undefined
formatter function The cell formatter function, take three parameters:
value: the field value.
rowData: the row record data.
rowIndex: the row index.

Code example:

$('#dg').datagrid({
	columns:[[
		{field:'userId',title:'User', width:80,
			formatter: function(value,row,index){
				if (row.user){
					return row.user.name;
				} else {
					return value;
				}
			}
		}
	]]
});
undefined
styler function The cell styler function, return style string to custom the cell style such as 'background:red'. The function take three parameter:
value: the field value.
rowData: the row record data.
rowIndex: the row index.

Code example:

$('#dg').datagrid({
	columns:[[
		{field:'listprice',title:'List Price', width:80, align:'right',
			styler: function(value,row,index){
				if (value < 20){
					return 'background-color:#ffee00;color:red;';
				}
			}
		}
	]]
});
undefined
sorter function The custom field sort function that used to do local sorting, take two parameters:
a: the first field value.
b: the second field value.

Code example:

$('#dg').datagrid({
	remoteSort: false,
	columns: [[
		{field:'date',title:'Date',width:80,sortable:true,align:'center',  
			sorter:function(a,b){  
				a = a.split('/');  
				b = b.split('/');  
				if (a[2] == b[2]){  
					if (a[0] == b[0]){  
						return (a[1]>b[1]?1:-1);  
					} else {  
						return (a[0]>b[0]?1:-1);  
					}  
				} else {  
					return (a[2]>b[2]?1:-1);  
				}  
			}  
		}
	]]
});
undefined
editor string,object Indicate the edit type. When string indicates the edit type, when object contains two properties:
type: string, the edit type, possible type is: text,textarea,checkbox,numberbox,validatebox,datebox,combobox,combotree.
options: object, the editor options corresponding to the edit type.
undefined

 

編輯器

Override defaults with $.fn.datagrid.defaults.editors.

 

Every editor has following actions:

名稱參數列表描述
init container, options Initialize the editor and return the target object.
destroy target Destroy the editor if necessary.
getValue target Get value from editor text.
setValue target , value Set value for editor.
resize target , width Resize the editor if necessary.

For example, the text editor is defined as following:

  1. $.extend($.fn.datagrid.defaults.editors, {
  2. text: {
  3. init: function(container, options){
  4. var input = $('<input type="text" class="datagrid-editable-input">').appendTo(container);
  5. return input;
  6. },
  7. destroy: function(target){
  8. $(target).remove();
  9. },
  10. getValue: function(target){
  11. return $(target).val();
  12. },
  13. setValue: function(target, value){
  14. $(target).val(value);
  15. },
  16. resize: function(target, width){
  17. $(target)._outerWidth(width);
  18. }
  19. }
  20. });

表格視圖

Override defaults with $.fn.datagrid.defaults.view.

The view is an object that will tell datagrid how to render rows. The object must defines the following functions:

名稱參數列表描述
render target, container, frozen Called when the data is loaded.
target: DOM object, the datagrid object.
container: the rows container.
frozen: indicate if to render the frozen container.
renderFooter target, container, frozen This is an option function to render row footer.
renderRow target, fields, frozen, rowIndex, rowData This is an option function and will be called by render function.
refreshRow target, rowIndex Defines how to refresh the specified row.
onBeforeRender target, rows Fires before the view is rendered.
onAfterRender target Fires after the view is rendered.

 

事件

The events extend from panel, below is the added events for datagrid.

名稱參數列表描述
onLoadSuccess data Fires when data is loaded successfully.
onLoadError none Fires when some error occur to load remote data.
onBeforeLoad param Fires before a request is made to load data. If return false the load action will be canceled.
onClickRow rowIndex, rowData Fires when user click a row, the parameters contains:
rowIndex: the clicked row index, start with 0
rowData: the record corresponding to the clicked row
onDblClickRow rowIndex, rowData Fires when user dblclick a row, the parameters contains:
rowIndex: the clicked row index, start with 0
rowData: the record corresponding to the clicked row
onClickCell rowIndex, field, value Fires when user click a cell.
onDblClickCell rowIndex, field, value Fires when user dblclick a cell.

Code example:

// when double click a cell, begin editing and make the editor get focus
$('#dg').datagrid({
	onDblClickCell: function(index,field,value){
		$(this).datagrid('beginEdit', index);
		var ed = $(this).datagrid('getEditor', {index:index,field:field});
		$(ed.target).focus();
	}
});
onSortColumn sort, order Fires when user sort a column, the parameters contains:
sort: the sort column field name
order: the sort column order
onResizeColumn field, width Fires when user resize the column.
onSelect rowIndex, rowData Fires when user select a row, the parameters contains:
rowIndex: the selected row index, start with 0
rowData: the record corresponding to the selected row
onUnselect rowIndex, rowData Fires when user unselect a row, the parameters contains:
rowIndex: the unselected row index, start with 0
rowData: the record corresponding to the unselected row
onSelectAll rows Fires when user select all rows.
onUnselectAll rows Fires when user unselect all rows.
onCheck rowIndex,rowData Fires when user check a row, the parameters contains:
rowIndex: the checked row index, start with 0
rowData: the record corresponding to the checked row
This event is available since version 1.3.
onUncheck rowIndex,rowData Fires when user uncheck a row, the parameters contains:
rowIndex: the unchecked row index, start with 0
rowData: the record corresponding to the unchecked row
This event is available since version 1.3.
onCheckAll rows Fires when user check all rows. This event is available since version 1.3.
onUncheckAll rows Fires when user uncheck all rows. This event is available since version 1.3.
onBeforeEdit rowIndex, rowData Fires when user start editing a row, the parameters contains:
rowIndex: the editing row index, start with 0
rowData: the record corresponding to the editing row
onAfterEdit rowIndex, rowData, changes Fires when user finish editing, the parameters contains:
rowIndex: the editing row index, start with 0
rowData: the record corresponding to the editing row
changes: the changed field/value pairs
onCancelEdit rowIndex, rowData Fires when user cancel editing a row, the parameters contains:
rowIndex: the editing row index, start with 0
rowData: the record corresponding to the editing row
onHeaderContextMenu e, field Fires when the header of datagrid is right clicked.
onRowContextMenu e, rowIndex, rowData Fires when a row is right clicked.

 

方法

名稱參數描述
options none Return the options object.
getPager none Return the pager object.
getPanel none Return the panel object.
getColumnFields frozen Return the column fields. If frozen setted to true the frozen column fields is returned.
Code example:
var opts = $('#dg').datagrid('getColumnFields');	// get unfrozen columns
var opts = $('#dg').datagrid('getColumnFields', true); // get frozen columns
getColumnOption field Return the specified column option.
resize param Do resize and do layout.
load param Load and show the first page rows. If the 'param' is specified, it will replace with the queryParams property. Usually do a query by passing some parameters, this method can be called to load new data from server.
$('#dg').datagrid('load',{
	code: '01',
	name: 'name01'
});
reload param Reload the rows. Same as the 'load' method but stay on current page.
reloadFooter footer Reload the footer rows. Code examples:
// update footer row values and then refresh
var rows = $('#dg').datagrid('getFooterRows');
rows[0]['name'] = 'new name';
rows[0]['salary'] = 60000;
$('#dg').datagrid('reloadFooter');

// update footer rows with new data
$('#dg').datagrid('reloadFooter',[
	{name: 'name1', salary: 60000},
	{name: 'name2', salary: 65000}
]);
loading none Display loading status.
loaded none Hide loading status.
fitColumns none Make columns auto expand/collapse to fit datagrid width.
fixColumnSize field Fix columns size. If 'field' parameter is not assigned, all columns size will be fixed.

Code example:

$('#dg').datagrid('fixColumnSize', 'name');  // fix the 'name' column size
$('#dg').datagrid('fixColumnSize');  // fix all columns size
fixRowHeight index Fix the specified row height. If 'index' parameter is not assigned, all rows height will be fixed.
freezeRow index Freeze the specify row that will always be displayed at the top when the datagrid is scrolled down. This method is available since version 1.3.2.
autoSizeColumn field adjusts the column width to fit the contents. This method is available since version 1.3.
loadData data Load local data, the old rows will be removed.
getData none Return the loaded data.
getRows none Return the current page rows.
getFooterRows none Return the footer rows.
getRowIndex row Return the specified row index, the row parameter can be a row record or an id field value.
getChecked none Return all rows where the checkbox has been checked. This method is available since version 1.3.
getSelected none Return the first selected row record or null.
getSelections none Return all selected rows, when no record selected, am empty array will return.
clearSelections none Clear all selections.
clearChecked none Clear all checked rows. This method is available since version 1.3.2.
scrollTo index Scroll to the specified row. This method is available since version 1.3.3.
highlightRow index Highlight a row. This method is available since version 1.3.3.
selectAll none Select all current page rows.
unselectAll none Unselect all current page rows.
selectRow index Select a row, the row index start with 0.
selectRecord idValue Select a row by passing id value parameter.
unselectRow index Unselect a row.
checkAll none Check all current page rows. This method is available since version 1.3.
uncheckAll none Uncheck all current page rows. This method is available since version 1.3.
checkRow index Check a row, the row index start with 0. This method is available since version 1.3.
uncheckRow index Uncheck a row, the row index start with 0. This method is available since version 1.3.
beginEdit index Begin editing a row.
endEdit index End editing a row.
cancelEdit index Cancel editing a row.
getEditors index Get the specified row editors. Each editor has the following properties:
actions: the actions that the editor can do, same as the editor definition.
target: the target editor jQuery object.
field: the field name.
type: the editor type, such as 'text','combobox','datebox', etc.
getEditor options Get the specified editor, the options contains two properties:
index: the row index.
field: the field name.

Code example:

// get the datebox editor and change its value
var ed = $('#dg').datagrid('getEditor', {index:1,field:'birthday'});
$(ed.target).datebox('setValue', '5/4/2012');
refreshRow index Refresh a row.
validateRow index validate the specified row, return true when valid.
updateRow param Update the specified row, the param contains following properties:
index: the row index to be updated.
row: the new row data.

Code example:

$('#dg').datagrid('updateRow',{
	index: 2,
	row: {
		name: 'new name',
		note: 'new note message'
	}
});
appendRow row Append a new row. The new row will be added to the last position:
$('#dg').datagrid('appendRow',{
	name: 'new name',
	age: 30,
	note: 'some messages'
});
insertRow param Insert a new row, the param contains following properties:
index: the row index to insert into, if not defined, append the new row.
row: the row data. Code examples:
// insert a new row at second row position
$('#dg').datagrid('insertRow',{
	index: 1,	// index start with 0
	row: {
		name: 'new name',
		age: 30,
		note: 'some messages'
	}
});
deleteRow index Delete a row.
getChanges type Get changed rows since the last commit. The type parameter indicate which type changed rows, possible value is: inserted,deleted,updated,etc. When the type parameter is not assigned, return all changed rows.
acceptChanges none Commits all the changes data since it was loaded or since the last time acceptChanges was called.
rejectChanges none Rolls back all the changes data since it was created, or since the last time acceptChanges was called.
mergeCells options Merge some cells to one cell, the options contains following properties:
index: the row index.
field: the field name.
rowspan: the rowspan count to be merged.
colspan: the colspan count to be merged.
showColumn field Display the specified column.
hideColumn field Hide the specified column.

您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 最近又把《大型網站技術架構》看了一遍.而中間讀了一本《電腦操作系統》的教材後,感覺對大型網站的技術架構有更深的瞭解。在此結合對這兩本書的理解做一些筆記 傳統的OS(Operator System)有四個基本的功能: a) 進程式控制制 b) 進程同步 c) 進程通信 d) 調度 2.存儲器管理 a) ...
  • 回到目錄 對於Lind.DDD架構,我之前寫了不少文章,對於它的Domain模式也介紹了不少,像之前的IEntity,ILogicDeleteBehavor,IModifyBehavor,IStatusBehavor和ISortBehavor都有自己的功能,只要實體實現對外的介面,就具有了某種特性或 ...
  • 遍曆數組通常使用for迴圈,ES5的話也可以使用forEach,ES5具有遍曆數組功能的還有map、filter、some、every、reduce、reduceRight等,只不過他們的返回結果不一樣。但是使用foreach遍曆數組的話,使用break不能中斷迴圈,使用return也不能返回到外層 ...
  • 一、Jquery的插件簡介 (一)什麼是插件 插件(Plug-in)是一種遵循一定的應用程式介面規範編寫出來的程式,是原有系統平臺或應用軟體平臺功能的一種擴展和補充。 註意!!其只能在程式規定的系統平臺下運行,而不能脫離指定平臺單獨利用。 (二)查找插件和幫助網址 1)http://jqueryui ...
  • ...
  • 先將表單數值轉換成數組存儲,存儲成的格式為[{"name":"","value":""},.....}] 將formArray轉換成Json格式 ...
  • 一、效果圖(如下)及使用的技術 實現用sass實現頁面中右側固定側邊欄的樣式,用require.js實現返回頂部的功能 二、sass 具體的sass的介紹就不多說了,大家可以參考sass官網介紹,下麵說一下sass的兩種編譯方法; a、koala編譯 koala 是一款桌面程式,支持 less 、 ...
  • 解決方法: 1.在父元素上加:overflow:hidden. 2.給父元素加border; 3.外容器上加上padding。 ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...