springMVC和easyUI结合使用的实例
1.首先,页面引入easyUI文件
<link rel="stylesheet" href="/js/easyui/themes/default/easyui.css"> <link rel="stylesheet" href="/js/easyui/themes/icon.css"> <script type="text/javascript" src="/js/easyui/jquery.min.js"></script> <script type="text/javascript" src="/js/easyui/jquery.easyui.min.js"></script> <script type="text/javascript" src="/js/easyui/locale/easyui-lang-zh_CN.js"></script>
2.页面中js代码如下
<script type="text/javascript"> $(function(){ $("#stuTable").datagrid({ idField:'id', columns:[[ {field:'ck',checkbox:'true',width:10,align:'center'}, {field:'createTime',title:'申请日期',width:50,align:'center'}, {field:'xcode',title:'申请编号',width:50,align:'center'}, {field:'stucode',title:'发票号',width:50,align:'center'}, {field:'status',title:'状态',width:50,align:'center', formatter:function(value,row,index){ switch(value) { case 0: return '上学'; break; case 1: return '毕业'; break; case 2: return '入学'; break; default: return '查看'; } } }, {field:'operation',title:'操作',width:50,align:'left', formatter:function(value,row,index){ var a = '<a href="/showStu.htm?id='+row.id+'&Tid='+row.Tid+'" title="查看" >查看</a>'; if(row.status == -1){ } return a; } }, ]] }); }); function search() { var time1 = $('#beginTime').datebox('getValue'); var time2 = $('#endTime').datebox('getValue'); if(time1!=''&&time2!=''&&time2<time1) { $.messager.alert("警告!","结束时间必须大于开始时间"); return; } $('#stuTable').datagrid('load',{ beginTime:time1, endTime:time2, xcode:$('#xcode').val(), stucode:$('#stucode').val(), status:$('#stuStatus').val() }); } function clear(){ $('#beginTime').datebox('setValue',""); $('#endTime').datebox('setValue',""); $('#xcode').val(""); $('#stuCode').val(""); $('#stuStatus').val(""); } </script>
3.页面中html代码如下
<div > <ul> <li class="sc"> <label for="field"><span class="t2">申请日期</span></label> <input type="text" name="beginTime" id="beginTime" editable="false" class="easyui-datebox" style="width:100px; height:30px;"> </li> <li class="sc"> <label for="field" ><span class="t2">至</span></label> <input type="text" name="endTime" id="endTime" editable="false" class="easyui-datebox" style="width:100px; height:30px;"> </li> <li class="sc"> <label for="field" ><span class="t2">申请编号</span></label> <input type="text" name="xcode" id="xcode" style="width:140px;" > </li> <li class="sc"> <label for="field" ><span class="t2">学生号</span></label> <input type="text" name="stuCode'" id="stuCode'" style="width:150px;" > </li> <li class="sc"> <label for="field" ><span class="t2">状 态</span></label> <div class="select" style=" width:100px;"> <select name="status" id="status"> <option value="">全部</option> <option value="0" <c:if test="${param.stuStatus eq 0 }">selected</c:if>>上学</option> <option value="1" <c:if test="${param.stuStatus eq 1 }">selected</c:if>>毕业</option> <option value="2" <c:if test="${param.stuStatus eq 2 }">selected</c:if>>入学</option> </select> </div> </li> <li> <a href="javascript:void(0)" onclick="search()">搜索</a> <a href="javascript:void(0)" onclick="clear()">清空</a> </li> </ul> </div> <div class="t2"> <table id="stuTable" title="学生列表" url="/studentlistData.htm" pageList="[10,20]" singleSelect="true" fitColumns="true" pagination="true" pageSize="10" loadMsg="加载中···" rownumbers="true" fitColumns="true" > </table> </div>
4.后台springMVC的代码
@RequestMapping("/studentlistData.htm") public void studentlistData(HttpServletRequest request,HttpServletResponse response) throws Exception{ try { response.setHeader("Cache-Control", "no-cache"); response.setContentType("text/json;charset=UTF-8"); request.setCharacterEncoding("UTF-8"); String page = request.getParameter("page"); String rows = request.getParameter("rows"); if(StringUtils.isEmpty(from)){ from ="0"; } if(rows.equals("NaN")){ rows="1"; } List<Student> list = invoicedService.getStudentListByPage(con,(Integer.parseInt(page)-1)*Integer.parseInt(rows),Integer.parseInt(rows)); long count = invoicedService.getAllCount(con); JSONArray jarray = new JSONArray(); JSONObject jobject = new JSONObject(); jobject.put("total",count); if(!list.isEmpty()){ int index = 1; for (Student s : list) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); JSONObject jo = new JSONObject(); jo.put("id", s.getId()); jo.put("Tid", s.getTeacher().getId()); jo.put("createTime", sdf.format(stucode.getCreateTime())); jo.put("xcode", s.getXcode()); jo.put("stuCode",s.getStuCode()); jo.put("status", s.getStatus()); jo.put("rows",index); jarray.add(jo); index++; } jobject.put("rows",jarray); } PrintWriter out = response.getWriter(); out.print(jobject); out.flush(); out.close(); } catch (Exception e) { } }
相关推荐
88274956 2020-11-03
runner 2020-09-01
梦的天空 2020-08-25
移动开发与培训 2020-08-16
ReunionIsland 2020-08-16
lyqdanang 2020-08-16
MyNameIsXiaoLai 2020-07-08
星辰的笔记 2020-07-04
csstpeixun 2020-06-28
letheashura 2020-06-26
liaoxuewu 2020-06-26
sunzhihaofuture 2020-06-21
FEvivi 2020-06-16
坚持着执着 2020-06-16
waterv 2020-06-14
xiaoge00 2020-06-14
firejq 2020-06-14
firstboy0 2020-06-14
e度空间 2020-06-12
zhongweinan 2020-06-10