{iconCls:'icon-edit',text:'修改', handler:function(){ type="edit"; //判断是否选中一条数据 var data = $('#dg').datagrid('getSelected'); if(data) { //alert(data); //设置主键字段只读 $("#sno").textbox({readonly:true}); $('#form1').form("reset"); $('#form1').form('load',{sno:data.sno,sname:data.sname,ssex:data.ssex,sbirthday:getDate(data.sbirthday),sclass:data.sclass}); //没有datebox // $('#form').form('load',data); $("#saveStu").dialog({title:'修改学生'}).dialog('open'); } else { $.messager.show({ title:'提示', msg:'请选中一条记录' }); } } },
<div class="easyui-dialog" id="saveStu" style="400px;height:200px;" title="添加学生" data-options="{closed:true,modal:true, buttons:[{text:'保存',iconCls:'icon-save',handler:function(){ $('#form1').form('submit',{ url:'SaveStudentServlet?type='+type, onSubmit:function(){ var isValid = $(this).form('validate'); if (!isValid){ $.messager.show({ title:'消息', msg:'数据验证未通过' }); } return isValid; }, success:function(data){ var msg = eval('('+data+')'); if(!msg.success) { alert(msg.message); } else { $('#dg').datagrid('reload'); $.messager.show({title:'提示',msg:msg.message}); $('#saveStu').dialog('close'); } }, }); }}, {text:'取消',iconCls:'icon-cancel',handler:function(){ $('#saveStu').dialog('close'); }}, ] }" >
servlet
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8"); response.setContentType("text/html"); String spage = request.getParameter("page"); String srows = request.getParameter("rows"); String sort = request.getParameter("sort"); String order = request.getParameter("order"); String sname_s = request.getParameter("sname_s"); if(sname_s!=null){ sname_s=new String(sname_s.getBytes("ISO-8859-1"),"UTF-8"); } String sclass_s = request.getParameter("sclass_s"); if(sclass_s!=null){ sclass_s=new String(sclass_s.getBytes("ISO-8859-1"),"UTF-8"); } System.out.println(sname_s+" "+sclass_s); if(spage!=null&&srows!=null) { int page =Integer.parseInt(spage); int rows =Integer.parseInt(srows); //对条件进行打包 Map<String,String> where = new HashMap<String,String>(); where.put("sname_s", sname_s); where.put("sclass_s", sclass_s); //组合排序语句 String ls=""; if(sort!=null) { ls = sort+" "+order; } String json = new StudentService().getPageJSON(page, rows, ls,where); response.getWriter().println(json); } else { response.getWriter().println("{'total':0,'row':[]}" ); } }
底层逻辑部分
//修改数据 public void update(Student stu) { init(); se.update(stu); destroy(); } //修改 public void updateStudent(Student stu) { new StudentDAO().update(stu); }