标签:lin hash tac container row 使用 匹配 情况下 grid
1、html
<div class="container"> <h3>学生成绩</h3> <!-- 查询块 --> <div class="row collapse" id="collapseFilter" aria-expanded="true"> <div class="col-md-12"> <h5>查询条件</h5> <div class="box-body"> <form class="form-inline" role="form"> <div class="form-group"> <label for="name" class="sr-only">姓名</label> <input id="name" type="text" class="form-control" placeholder="请输入姓名模糊查询" /> </div> <button id="btn_search" type="button" class="btn btn-primary btn-sm" onclick="search();"> <span class="glyphicon glyphicon-search" aria-hidden="true"></span>查询 </button> <button id="btn_clean_search" type="button" class="btn btn-danger btn-sm" onclick="clearSearch();">清空条件</button> </form> </div> </div> </div> <!-- 表格块 --> <div class="row"> <div class="col-md-12"> <div id="toolbar"> <!-- 工具栏 --> <button type="button" class="btn btn-primary btn-sm" onclick="addData();"><span class="fa fa-plus" aria-hidden="true"></span> 新增 </button> <button type="button" class="btn btn-primary btn-sm" onclick="product.editDataByMenu();"><span class="fa fa-pencil" aria-hidden="true"></span> 修改 </button> <button type="button" class="btn btn-primary btn-sm" onclick="product.deleteDataByMenu();"><span class="fa fa-trash" aria-hidden="true"></span> 删除 </button> <button type="button" class="btn btn-primary btn-sm" data-toggle="collapse" data-target="#collapseFilter" aria-expanded="true" aria-controls="collapseFilter"> <i class="fa fa-filter"></i> 查询 </button> </div> <!-- 表格 --> <table id="mytable" class="table table-hover"></table> </div> </div> </div>
2、js
<script type="text/javascript"> var $table = $(‘#mytable‘), $remove = $(‘#remove‘), selections = []; $(function(){ initTable(null); $table.bootstrapTable(‘hideLoading‘); }); function initTable(searchArgs) { $table.bootstrapTable(‘destroy‘); $table.bootstrapTable({ url: ‘http://localhost:8080/ssh/grid‘, method: ‘post‘, contentType: "application/x-www-form-urlencoded", dataType: "json", striped: true,//是否显示行间隔色 sortable: true, //是否启用排序 sortName: "id",//排序字段 sortOrder: "desc", //排序方式 cache: false,//是否使用缓存 uniqueId: "id",//每行的唯一标识 toolbar: "#toolbar",//指定工具栏 showColumns: true,//显示隐藏列列选择按钮 search: false, //是否显示搜索框 showRefresh: false, //显示刷新按钮 showToggle: false,//切换显示样式 showFooter: false, //显示Table脚部 pagination: true,//是否显示分页 showPaginationSwitch: false, //是否显示分页按钮 clickToSelect: false, //是否启用点击选中行 minimumCountColumns: 2, //最少要显示的列数 undefinedText: ‘-‘, //cell没有值时显示 sidePagination: "server", //分页方式:client客户端分页,server服务端分页 pageSize: 2,//每页的记录行数 pageNumber: 1, //初始化加载第1页,默认第1页 pageList: "[5,10,20]",//可供选择的每页的行数 height:tableHeight(), iconsPrefix: ‘glyphicon‘, /* queryParamsType的默认值为 ‘limit‘ ,在默认情况下 传给服务端的参数为:offset,limit,sort 设置为 ‘‘ 在这种情况下传给服务器的参数为:pageSize,pageNumber */ queryParamsType:‘‘, queryParams: function queryParams(params) { var param = { pageNumber: params.pageNumber, pageSize: params.pageSize, sortName:this.sortName, sortOrder:this.sortOrder }; for(var key in searchArgs){ param[key]=searchArgs[key] } return param; }, editable:false,//开启编辑模式 columns: [{ field: ‘state‘, checkbox: true, align: ‘center‘, valign: ‘middle‘ }, { title: ‘名字‘, field: ‘name‘, align: ‘center‘, valign: ‘middle‘, sortable: true }, { title: ‘科目‘, field: ‘subject‘, align: ‘center‘, valign: ‘middle‘, sortable: true }, { title: ‘成绩‘, field: ‘score‘, align: ‘center‘, valign: ‘middle‘, sortable: true }], onLoadSuccess: function () { //加载成功时执行 console.log("加载成功!"); }, onLoadError: function () { //加载失败时执行 console.log("加载失败!"); }, formatLoadingMessage: function () { //正在加载 return "请稍等,正在加载中..."; }, formatNoMatches: function () { //没有匹配的结果 return ‘无符合条件的记录‘; } }); } //获取窗口高度 function tableHeight() { return $(window).height() - 160; } //搜索分页查询 function search(){ var searchArgs={ keyName:"name", keyValue:$("#name").val() }; initTable(searchArgs); } //清空条件按钮点击事件 function clearSearch(){ $(‘#name‘).val(""); search(); } </script>
3、action
public void grid() throws IOException { System.out.println("sortName:"+sortName); System.out.println("sortOrder:"+sortOrder); System.out.println("keyName:"+keyName); System.out.println("keyValue:"+keyValue); Map<String, Object> params=new HashMap<String, Object>(); Map<String, Object> condition=new HashMap<String, Object>(); int startSize=(pageNumber-1)*pageSize; params.put("startSize", startSize); params.put("pageSize", pageSize); params.put("sortName", sortName); params.put("sortOrder", sortOrder); condition.put("keyName", keyName); condition.put("keyValue", keyValue); Gson gson= new Gson(); String json = ""; json= gson.toJson(scoreService.findGrid(params,condition)); System.out.println("获取的数据:"+json); super.toAjax(json); }
4、service
public Map<String, Object> findGrid(Map<String, Object> params,Map<String, Object> condition) { // TODO Auto-generated method stub Map<String,Object> result = new HashMap<String,Object>(); int total=scoreDao.findCount(condition).size(); List<Score> rows=scoreDao.findGrid(params,condition); result.put("total",total); result.put("rows",rows); return result; }
5、dao
public List<Score> findGrid(Map<String, Object> params,Map<String, Object> condition) { // TODO Auto-generated method stub Session session=null; Query query = null; try{ session=sessionFactory.openSession(); //得到session对象 int startSize = (Integer) params.get("startSize"); int pageSize = (Integer) params.get("pageSize"); String sortName = (String) params.get("sortName"); String sortOrder = (String) params.get("sortOrder"); String keyName = (String) condition.get("keyName"); String keyValue = (String) condition.get("keyValue"); if( keyValue == null || "".equals(keyValue) || keyValue.length()==0){//没有查询条件下的总数量 query=session.createQuery("from Score order by "+ sortName +" "+sortOrder ); }else{ query=session.createQuery("from Score where "+keyName+" like ‘%"+ keyValue+ "%‘"+" order by "+ sortName +" "+sortOrder ); } query.setFirstResult(startSize); //设置这一页显示的第一条记录的索引 query.setMaxResults(pageSize); //这一页显示的记录个数 List<Score> list=query.list(); return list; }catch(Exception ex){ ex.printStackTrace(); return null; }finally{ session.close(); } } @Override public List<Score> findCount(Map<String, Object> condition) { // TODO Auto-generated method stub Session session=null; Query query = null; try{ session=sessionFactory.openSession(); //得到session对象 String keyName = (String) condition.get("keyName"); String keyValue = (String) condition.get("keyValue"); if( keyValue == null || "".equals(keyValue) || keyValue.length()==0){//没有查询条件下的总数量 query=session.createQuery("from Score"); }else{ query=session.createQuery("from Score where "+keyName+" like ‘%"+ keyValue+ "%‘"); } List<Score> list=query.list(); return list; }catch(Exception ex){ ex.printStackTrace(); return null; }finally{ session.close(); } }
标签:lin hash tac container row 使用 匹配 情况下 grid
原文地址:http://www.cnblogs.com/liuzhenping/p/7719734.html