datagrid界面,链接数据库读取数据

1、学生列表的 HTML部分
<script type="text/javascript">
$(function(){
//创建dataGrid
$("#dg").datagrid({
url:'StudentServlet', //数据来源
//冻结列
frozenColumns:[[
{field:'id',checkbox:true},
{field:'sno',title:'学号',width:100,sortable:true} ]], \\可排列 //列的定义
columns:[[ {field:'sname',title:'姓名',width:100},
{field:'sclass',title:'班级',width:100,align:'right'},
{field:'ssex',title:'性别',width:100,align:'center',hidden:false},
{field:'sbirthday',title:'生日',width:100,align:'center' }
]],
fitColumns:true, //不能和冻结列同时设置
striped:true,//斑马线效果
idField:'sno',//主键列,
rownumbers:true,//显示行号
singleSelect:false,//是否单选
pagination:true,//显示分页栏
pageList:[5,10,20],//每页行数选择列表
pageSize:5,//初始页面大小
remoteSort:false,//是否服务器端排序
toolbar:[
{iconCls:'icon-edit',text:'跳到第2页',
handler:function(){$('#dg').datagrid('gotoPage', 2)} },
{iconCls:'icon-edit',text:'跳到第3页',
handler:function(){$('#dg').datagrid('gotoPage', 3)} }
]
});
})
</script>
数据表格<br>
<table id="dg"></table>
</body>
2、StudentServlet部分(数据来源)
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"); \\获取page
String srows = request.getParameter("rows"); \\获取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,'row':[]}" );
}
}

3、StudentService() 类
public class StudentService {
//查询分页数据
//返回JSON
public String getPageJSON(int page,int rows)
{
String rtn = "{\"total\":0,\"row\":[]}" ;
int total = new StudentDAO().getTotal();
if(total > 0 )
{
List<Student> ls = new StudentDAO().getPageList(page, rows);
String ls_json = JSONArray.toJSONString(ls);
rtn = "{\"total\":"+total+",\"rows\":"+ls_json+"}"; \\规范 json 格式
}
return rtn;
}
}
4、StudentDAO()类内的 getPageList(获取分页数据集合) 和 getTotal(获取数据条数) 的方法
//获取分页数据集合
public List<Student> getPageList(int page, int rows)
{
List<Student> rtn = new ArrayList<Student>(); init(); rtn = se.createQuery("from Student order by sno").
setMaxResults(rows).setFirstResult((page-1)*rows)
.list(); destroy(); return rtn; } //获取数据条数
public int getTotal()
{
int rtn = 0; init(); List<Object> lo = se.createQuery("select count(1) from Student").list(); if(lo!=null&&lo.size()>0)
{
rtn = Integer.parseInt(lo.get(0).toString());
} destroy(); return rtn;
}
datagrid界面,链接数据库读取数据的更多相关文章
- echarts通过ajax向服务器发送post请求,servlet从数据库读取数据并返回前端
1.echarts的官网上的demo,都是直接写死的随机数据,没有和数据库的交互,所以就自己写了一下,ok,我们开始一步一步走一遍整个流程吧. 就以官网最简单的那个小demo来做修改吧.官网上的小de ...
- 课堂测试_WEB界面链接数据库
课堂测试_WEB界面链接数据库 一,题目: 一. 考试要求: 1登录账号:要求由6到12位字母.数字.下划线组成,只有字母可以开头:(1分) 2登录密码:要求显示“• ”或“*”表示输入位数,密码要求 ...
- 10天学会phpWeChat——第三天:从数据库读取数据到视图
在第二天,我们创建了我们的第一个phpWeChat功能模块,但是比较简单.实际生产环境中,我们不可能有如此简单的需求.更多的情况是数据存储在MySql数据库中,我们开发功能模块的作用就是将这些数据从M ...
- C#实现从数据库读取数据到Excel
用第三方组件:NPOI来实现 先去官网:http://npoi.codeplex.com/下载需要引入dll(可以选择.net2.0或者.net4.0的dll),然后在网站中添加引用.使用 NPOI ...
- JMeter 参数化之利用JDBCConnectionConfiguration从数据库读取数据并关联变量
参数化之利用DBC Connection Configuration从数据库读取数据并关联变量 by:授客 QQ:1033553122 1. 下载mysql jar包 下载mysql jar包 ...
- Python写的链接数据库存取数据
Python写的链接数据库存取数据 #!/usr/bin/python # -*- coding: UTF-8 -*- from __future__ import print_function im ...
- Android打开数据库读取数据
打开数据库读取数据 private MyDatabaseHelper dbHelper; dbHelper=new MyDatabaseHelper(this,"List.db", ...
- CI,从数据库读取数据
1.准备数据库,(用户,密码,数据库服务的地址) 2.CI链接数据库,配置database.php(配置文件) //application/config/database.php 3.准备 ...
- SQL Server数据库读取数据的DateReader类及其相关类
之前学了几天的SQL Server,现在用C#代码连接数据库了. 需要使用C#代码连接数据库,读取数据. 涉及的类有: ConfigurationManage SqlConnection SqlCom ...
随机推荐
- 【字符串匹配】KMP算法和next数组的c/c++实现
KMP算法基本思想有许多博客都写到了,写得也十分形象,不懂得可以参考下面的传送门,我就不解释基本思想了.本文主要给出KMP算法及next数组的计算方法(主要是很多网上的代码本人(相信应该是许多人吧)看 ...
- C++-Qt【2】-实现一个简单的记事本
用Qt实现一个简单的记事本: #include "helloqt.h" #include <qfiledialog.h> #include <qfile.h> ...
- 了解vmware tools
了解vmware tools vmware tools是虚拟机VMware Workstation自带的一款工具,它的作用就是使用户可以从物理主机直接往虚拟机里面拖文件.如果不安装它,我们是无法进行虚 ...
- CF2.C(二分贪心)
C. Road to Cinema time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Web 入门之 XML
160916 1. 什么是XML? XML 是 EXtensible Markup Language 的缩写,称为可扩展标记语言,所谓可扩展指用户可根据XML规则自定义标记.例子1-1 = ...
- 爬虫初探(2)之requests
关于请求网络,requests这个库是爬虫经常用到的一个第三方库. import requests url = 'http://www.baidu.com' #这里用get方法用来请求网页,其他还有p ...
- console对象-转
console对象 来自<JavaScript 标准参考教程(alpha)>,by 阮一峰 目录 开发者工具 console对象 console.log() console.debug() ...
- 输出 n=6 的三角数字阵(JAVA基础回顾)
package itcast.feng; import java.util.Scanner; //需求:输出 n=6 的三角数字阵 //1 //2 3 //4 5 6 //7 8 9 10 //11 ...
- Python Django Apache配置
项目结构目录: Apache 安装配置目录: C:\Apache2.2\conf\httpd.conf LoadModule wsgi_module modules/mod_wsgi.soWSGISc ...
- Centos7下安装mono3.10.0
mono 3.10.0 正式发布:性能进一步改进,以前已经写过一篇 Centos 7.0 安装Mono 3.4 和Jexus 5.6.下面我们在CentOS 7上通过源码安装Mono 3.10, 需 ...