EasyUI 页面分页
DAO
package com.hanqi.dao; import java.util.ArrayList;
import java.util.List; import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry; import com.hanqi.entity.Region;
import com.hanqi.entity.Student; public class StudentDAO { Configuration cfg = null;
ServiceRegistry sr = null;
SessionFactory sf = null;
Session se =null;
Transaction tr = null; public StudentDAO()//注册服务
{
//1.加载配置文件
cfg = new Configuration().configure();
//2.注册服务
sr = new StandardServiceRegistryBuilder()
.applySettings(cfg.getProperties()).build();
}
//初始化
private void init()
{
sf= cfg.buildSessionFactory(sr);
se = sf.openSession();
tr = se.beginTransaction();
}
//提交和释放
private void destroy()
{
tr.commit();//提交事务
se.close();
sf.close();
} //获取分页数据集合列表
public List<Student> getPageList(int page , int rows)
{
init();
List<Student> rtn = new ArrayList<>();
rtn = se.createQuery("from Student").setMaxResults(rows)//每页行数
.setFirstResult((page-1)*rows).list();//其实页码 destroy();
return rtn;
} //获取数据条数
public int getTotal()
{
int rtn= 0;
init();
//获取Query对对象,定义集合并实例化
List<Object> lo = se.createQuery("select count(1) from Student").list(); if(lo != null && lo.size() > 0)
{
rtn = Integer.parseInt(lo.get(0).toString());//转换成int并赋值
} destroy(); return rtn;
}
}
service
package com.hanqi.service; import java.util.ArrayList;
import java.util.List; import com.alibaba.fastjson.JSONArray;
import com.hanqi.dao.StudentDAO;
import com.hanqi.entity.Student; public class StudentService { PageJSON<Student> lls = new PageJSON<Student>();
//查询分页数据
//返回JSON
public String getPageJSON(int page, int rows)
{ String rtn = "{total:0,rows:[]}";//空的JSON对象 int total = new StudentDAO().getTotal();
if(total>0)
{
List<Student> ls = new StudentDAO().getPageList(page, rows); String ls_json = JSONArray.toJSONString(ls);//转成JSON格式 //转义字符,转成JSON读取的格式 rtn = "{\"total\":"+total+",\"rows\":"+ls_json+"}" ; } return rtn;
} }
Servlet
package com.hanqi.web; import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import com.hanqi.service.StudentService; /**
* Servlet implementation class StudentServlet
*/
public class StudentServlet extends HttpServlet {
private static final long serialVersionUID = 1L; /**
* @see HttpServlet#HttpServlet()
*/
public StudentServlet() {
super();
// TODO Auto-generated constructor stub
} 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");//每页行数 if(spage!= null && srows != null)
{
//转型
int page = Integer.parseInt(spage);
int rows = Integer.parseInt(srows); String json = new StudentService().getPageJSON(page, rows);
response.getWriter().println(json);
}
else
{
response.getWriter().println("{total:0,rows:[]}");
}
} /**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
} }
页面
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<!-- 顺序不可以乱 -->
<!-- 1.jQuery的js包 -->
<script type="text/javascript" src="jquery-easyui-1.4.4/jquery.min.js"></script>
<!-- 2.css资源 -->
<link rel="stylesheet" type="text/css" href="jquery-easyui-1.4.4/themes/default/easyui.css">
<!-- 3. 图标资源 -->
<link rel="stylesheet" type="text/css" href="jquery-easyui-1.4.4/themes/icon.css">
<!-- 4.easyui的js包 -->
<script type="text/javascript" src="jquery-easyui-1.4.4/jquery.easyui.min.js"></script>
<!-- 5.本地语言 -->
<script type="text/javascript" src="jquery-easyui-1.4.4/locale/easyui-lang-zh_CN.js"></script>
</head>
<body>
<script type="text/javascript">
$(function(){ $("#hh").datagrid({ url:'StudentServlet',
//冻结列
frozenColumns:[[
{field:'id',checkbox:true},//复选框
{field:'sno',title:'学号',width:100} ]],
//定义列
columns:[[ {field:'sname',title:'姓名',width:200,align:'center'},
{field:'ssex',title:'性别',width:200,align:'center',
formatter: function(value,row,index){
if(value == 'f')
{
return '男';
}
else if(value == 'm')
{
return '女';
}
else if(value == '男')
{
return '男';
}
else if(value == '女')
{
return '女';
}
else
{
return '哈哈';
} },
styler:function(value,row,index){
if(value=='男')
{
return 'background-color:#ccccff;color:red;'; }
else if(value == 'f')
{
return 'background-color:#ccccff;color:red;';
}
}
} , {field:'sbirthday',title:'生日',width:200,align:'right'},
{field:'sclass',title:'班级',width:200,align:'right'} ]] ,
fitColumns:false, //列自适应宽度,不能和冻结列同时设置为true
striped:true, //斑马线
idField:'sno', //主键列
rownumbers:true, //显示行号
singleSelect:false, //是否单选
pagination:true, //分页栏
pageList:[8,16,24,32] , //每页行数选择列表
pageSize:8 , //初始每页行数
remoteSort:false, //是否服务器端排序,设成false才能客户端排序
//sortName:'unitcost', //定义哪些列可以进行排序。 toolbar:[
{
iconCls:'icon-add',
text:'添加',
handler:function(){
alert('添加按钮被点击')},
},
{
iconCls:'icon-edit',
text:'修改',
handler:function(){
alert('修改按钮被点击')},
},
{
iconCls:'icon-delete',
text:'删除',
handler:function(){
alert('删除按钮被点击')},
}
],
});
}) </script>
<table id="hh"></table>
</body>
</html>


EasyUI 页面分页的更多相关文章
- EasyUI DataGrid分页数据绑定
记录东西感觉很痛苦,总结东西很痛苦,麻烦,不过为了下次的方便和知识的牢固以后要坚持总结. EasyUI DataGrid分页数据绑定 在解决方案中新建两个文件FormMain.aspx(html也可以 ...
- asp.net mvc easyui datagrid分页
提到 asp.net mvc 中的分页,很多是在用aspnetpager,和easyui datagrid结合的分页却不多,本文介绍的是利用easyui 中默认的分页控件,实现asp.net mvc分 ...
- EasyUI Datagrid 分页显示(客户端)
转自:https://blog.csdn.net/metal1/article/details/17536185 EasyUI Datagrid 分页显示(客户端) By ZYZ 在使用JQuery ...
- 本人为项目组制定的一份页面优化指南(easyui页面优化方案)
#本人为项目组制定的一份页面优化指南(easyui页面优化方案) ##背景 这是一篇我之前为项目组制定的页面优化指南,主要是面向表单页面,典型的像[注册用户](https://passport.cnb ...
- EasyUI datagrid 分页Json字符串格式
//EasyUI datagrid 分页Json字符串格式 //{"total":xx,"rows":[{...},{...}]} total:总数 rows: ...
- 基于视觉的Web页面分页算法VIPS的实现源代码下载
基于视觉的Web页面分页算法VIPS的实现源代码下载 - tingya的专栏 - 博客频道 - CSDN.NET 基于视觉的Web页面分页算法VIPS的实现源代码下载 分类: 技术杂烩 2006-04 ...
- js 将很长的内容进行页面分页显示
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- easyUI的分页,只显示第X 共Y页。改为显示 第X 页 共Y页
如下图,easyUI的分页,只显示第X 共Y页. 需求需要显示 第X 页 共Y页. 解决办法:在easyui-lang-zh_CN.js更改以下代码,即可.也就是在 “共{pages}页”前面加个 “ ...
- easyui页面上显示和PL/SQL编码问题
在页面上,只需要显示人们看的懂的文字就行,但是在数据库里面就不一定了,一般情况下,在数据库里面存字母,数字等除了汉字以外的字符,存汉字有个问题,就是有时候不同oracle数据库的客户端会出现乱码问题: ...
随机推荐
- tyvj1938 最优战舰
描述 太空战队顺利地完成了它的第一次使命,这一行动的受益者陆军本部当即决定,请陆军的战士们投票选出最优战舰并报司令总部进行表彰.为防止有人利用高科技手段造假,陆军本部决定使用最原始的方法进行投票.可不 ...
- codevs2777 栅栏的木料
题目描述 Description 农民John准备建一个栅栏来围住他的牧场.他已经确定了栅栏的形状,但是他在木料方面有些问题.当地的杂货储存商扔给John一些木板,而John必须从这些木板中找出尽可能 ...
- spark安装(实战)
sparksql+hive :http://lxw1234.com/archives/2015/06/294.htm 1,安装scala http://scala-lang.org/download/ ...
- Linux文件查找命令 find 详解
关于find命令 由于find具有强大的功能,所以它的选项也很多,其中大部分选项都值得我们花时间来了解一下.即使系统中含有网络文件系统( NFS),find命令在该文件系统中同样有效,只你具有相应的权 ...
- 【Alpha】Daily Scrum Meeting第五次
一.本次Daily Scrum Meeting主要内容 每个人学习情况 任务安排 界面设计问题,怎样让界面更好看? 二.任务安排 学号尾数 昨天做的任务 今天的任务 明天的任务 612 时间轴控件优化 ...
- 基于浏览器的HTML5地理定位
基于浏览器的HTML5地理定位 地理位置(Geolocation)是 HTML5 的重要特性之一,提供了确定用户位置的功能,借助这个特性能够开发基于位置信息的应用.今天这篇文章向大家介绍一下 HTML ...
- 如何查看oracle 的package源码
select text from dba_source t where t.TYPE = 'PACKAGE BODY' and name ='EMR_RECORD_INPUT' order by li ...
- HDU 4946 Area of Mushroom(构造凸包)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4946 题目大意:在一个平面上有n个点p1,p2,p3,p4....pn,每个点可以以v的速度在平面上移 ...
- url和urn和uri
1.需求 理清三者的关系 2.例子 3.说明 url是资源的位置(包含scheme),urn表示资源的名字.url是唯一的.urn不是. 他们2个都是uri的子集 参考资料:https://danie ...
- Linux下对比两个文件夹的方法
最近拿到一份源代码,要命的是这份源代码是浅克隆模式的git包,所以无法完整显示里面的修改的内容. 今天花了一点点时间,找了一个在Linux对比两个文件夹的方法. 其实方法很简单,用meld 去对比两个 ...