SpringBoot集成Jquery easyUI:二、创建 CRUD 数据网格

    xiaoxiao2025-08-05  11

    在上一章节中,我们使用对话框(dialog)组件创建了 CRUD 应用来创建和编辑用户信息。本教程我们将告诉您如何创建一个 CRUD 数据网格(DataGrid)。我们将使用 可编辑的数据网格(DataGrid)插件 来完成这些 CRUD 操作动作。

    步骤 1:在 HTML 标签中定义数据网格(DataGrid)

    <table id="dg" title="My Users" style="width:700px;height:390px" toolbar="#toolbar" pagination="true" idField="id" rownumbers="true" fitColumns="true" singleSelect="true"> <thead> <tr> <th field="firstname" width="50" editor="{type:'validatebox',option:{required:true}}">First Name</th> <th field="lastname" width="50" editor="{type:'validatebox',option:{required:true}}">Last Name</th> <th field="phone" width="50" editor="text">Phone</th> <th field="email" width="50" editor="{type:'validatebox',options:{validType:'email'}}">Email</th> </tr> </thead> </table> <div id="toolbar"> <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" οnclick="javascript:$('#dg').edatagrid('addRow')">New</a> <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" οnclick="javascript:$('#dg').edatagrid('destroyRow')">Destroy</a> <a href="#" class="easyui-linkbutton" iconCls="icon-save" plain="true" οnclick="javascript:$('#dg').edatagrid('saveRow')">Save</a> <a href="#" class="easyui-linkbutton" iconCls="icon-undo" plain="true" οnclick="javascript:$('#dg').edatagrid('cancelRow')">Cancel</a> </div>

    步骤 2:使用可编辑的数据网格(DataGrid)

    <script type="text/javascript"> $(function(){ $('#dg').edatagrid({ url:'get_users', saveUrl:'save_user', updateUrl:'update_user', destroyUrl:'remove_user' }); }); </script>我们应该提供 'url'、'saveUrl'、'updateUrl' 和 'destroyUrl' 属性来编辑数据网格(DataGrid):

    url:从服务器端检索用户数据。saveUrl:保存一个新的用户数据。updateUrl:更新一个已存在的用户数据。destroyUrl:删除一个已存在的用户数据。 使用前一章UserRestController中提供的方法。

    步骤 3:暴露功能

    在DataGridController中

    @GetMapping("easyui-datagrid-crud2-1.html") public String jeasyui_app_crud2_1(Map<String, Object> model){ return "datagrid/crud2_1"; }

    代码存在在https://git.oschina.net/lxhjh/easyUI.git的CRUDDataGrid-160815中.

    转载请注明原文地址: https://ju.6miu.com/read-1301435.html
    最新回复(0)