Easyui的增删改查

本文介绍如何使用Easyui的datagrid, dialog和form布局,实现前后端分离的增删改查功能。通过form和dialog进行界面布局,借助datagrid进行数据回显和传递操作所需值,结合UserDao、UserAction、userManage.js和userManage.jsp实现完整的功能。" 108446661,8218591,Java将Long型时间戳转换为年月日时分秒毫秒格式,"['Java', '日期处理']
摘要由CSDN通过智能技术生成

重点:
我们今天用easyui来实现增删改查
我们今天要用到的布局有datagrid,dialog,form布局,用这几个控件完成一个简单的布局
第二个重点:
1.实现前后端的分离
我们要如何实现呢,接下来
思路:
首先利用form 和dialog进行布局,然后利用datadrid进行数据的回显以及传递数据操作所需要的值,然后我们利用修改传递过来的值进行增删改查。
UserDao


package com.liuxia.dao;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
public class UserDao extends JsonBaseDao {

public List<Map<String, Object>> list(Map<String, String[]> paMap,PageBean pageBean) throws InstantiationException, IllegalAccessException, SQLException{
  String sql ="select * from t_easyui_user_version2 where true ";
  String uid= JsonUtils.getParamVal(paMap,"uid");
  String upwd= JsonUtils.getParamVal(paMap,"upwd");
  if(StringUtils.isNotBlank(uid)) {
sql +=" and uid = "+uid;
  }
  if(StringUtils.isNotBlank(upwd)) {
   sql +=" and upwd ="+upwd;
  }
 return super.executeQuery(sql, pageBean);

 }

/**
  * 修改
  * @param paMap
  * @return
  * @throws NoSuchFieldException
  * @throws SecurityException
  * @throws IllegalArgumentException
  * @throws IllegalAccessException
  * @throws SQLException
  */
  public int edit(Map<String, String[]> paMap) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, SQLException {
  String sql= "update t_easyui_user_version2 set uid=?,uname=?,upwd=? where serialno=?"; 
  return super.executeUpdate(sql,new String[] {"uid","uname","upwd","SerialNo"}, paMap);
 }

/**
  * 删除
  * @param paMap
  * @return
  * @throws NoSuchFieldException
  * @throws SecurityException
  * @throws IllegalArgumentException
  * @throws IllegalAccessException
  * @throws SQLException
  */

public int del(Map<String, String[]> paMap) throws Exception, SecurityException, IllegalArgumentException, IllegalAccessException, SQLException {
  String sql ="delete from t_easyui_user_version2 where SerialNo =? ";
  return super.executeUpdate(sql, new String[] {"SerialNo"} , paMap);
 }

/**
  * 添加
  * @param paMap
  * @return
  * @throws Exception
  * @throws SecurityException
  * @throws IllegalArgumentException
 
我可以回答这个问题。以下是一个简单的 easyui 增删改查实现的示例代码: HTML 代码: ``` <div class="easyui-layout" style="width:100%;height:100%;"> <div region="west" split="true" title="菜单" style="width:200px;"> <ul id="menu"></ul> </div> <div region="center" title="内容"> <table id="dg"></table> <div id="toolbar"> <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newUser()">新增</a> <a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editUser()">编辑</a> <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyUser()">删除</a> </div> </div> </div> ``` JS 代码: ``` $(function(){ $('#menu').tree({ url:'menu.json', onClick:function(node){ $('#dg').datagrid({ url:'get_users.php?menu='+node.id, fit:true, fitColumns:true, singleSelect:true, rownumbers:true, pagination:true, toolbar:'#toolbar', columns:[[ {field:'id',title:'编号',width:50}, {field:'name',title:'姓名',width:100}, {field:'sex',title:'性别',width:50}, {field:'age',title:'年龄',width:50}, {field:'phone',title:'电话',width:100}, {field:'email',title:'邮箱',width:150}, {field:'address',title:'地址',width:200}, {field:'remark',title:'备注',width:200} ]] }); } }); }); function newUser(){ $('#dlg').dialog('open').dialog('setTitle','新增'); $('#fm').form('clear'); url = 'save_user.php'; } function editUser(){ var row = $('#dg').datagrid('getSelected'); if (row){ $('#dlg').dialog('open').dialog('setTitle','编辑'); $('#fm').form('load',row); url = 'update_user.php?id='+row.id; } } function saveUser(){ $('#fm').form('submit',{ url: url, onSubmit: function(){ return $(this).form('validate'); }, success: function(result){ var result = eval('('+result+')'); if (result.errorMsg){ $.messager.show({ title: 'Error', msg: result.errorMsg }); } else { $('#dlg').dialog('close'); $('#dg').datagrid('reload'); } } }); } function destroyUser(){ var row = $('#dg').datagrid('getSelected'); if (row){ $.messager.confirm('Confirm','Are you sure you want to delete this user?',function(r){ if (r){ $.post('destroy_user.php',{id:row.id},function(result){ if (result.success){ $('#dg').datagrid('reload'); } else { $.messager.show({ title: 'Error', msg: result.errorMsg }); } },'json'); } }); } } ```
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值