SSH后台管理系统,实现查询+分页
一个搜索框,然后会获取大量信息,将信息进行分页,每一页显示固定条数。
mysql中使用“like”和“%%”进行模糊匹配,用“limit”进行分页。
1.首先创建一个页面信息的实体类,代码如下:
import java.util.List;
public class PageResult1 {
private List dataList;//满足查询条件后的所有数据
public List getDataList() {
return dataList;
}
public void setDataList(List dataList) {
this.dataList = dataList;
}
//当前页
private int currentPage;
//首页
private int firstPage=1;
//尾页
private int lastPage;
//上一页
private int prePage;
//下一页
private int nextPage;
//总数
private int totalCount;
//每页条数
private int pageSize=2;
public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public int getFirstPage() {
return firstPage;
}
public void setFirstPage(int firstPage) {
this.firstPage = firstPage;
}
public int getLastPage() {
return lastPage;
}
public void setLastPage(int lastPage) {
this.lastPage = lastPage;
}
public int getPrePage() {
return prePage;
}
public void setPrePage(int prePage) {
this.prePage = prePage;
}
public int getNextPage() {
return nextPage;
}
public void setNextPage(int nextPage) {
this.nextPage = nextPage;
}
public int getTotalCount() {
return totalCount;
}
public void setTotalCount(int totalCount) {
this.totalCount = totalCount;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public PageResult1(List dataList, int currentPage,int pageSize, int totalCount) {//只有datalist和totalCount需要自己写方法得到
super();
this.dataList=dataList;
this.currentPage = currentPage;
this.firstPage = 1;
this.pageSize = pageSize;
this.totalCount = totalCount;
//这边要按顺序写,用myeclipse自动生成的有参构造,顺序会有问题,这样可能无法计算出需要的数值
this.prePage = currentPage>1 ? currentPage-1 : currentPage;
this.lastPage = totalCount%pageSize==0 ? totalCount/pageSize : totalCount/pageSize+1; this.nextPage = currentPage<lastPage ? currentPage+1 : currentPage;
}
public PageResult1() {
super();
// TODO Auto-generated constructor stub
}
}
2.编写dao实现类中的方法
需要两个方法分别是:
//查询某个商品的数量
public int findGoods(Integer number);
//分页
public List<Goodsdetail> limit(Integer number,int currentPage,int pageSize);
public class GoodsDetailImpl implements IGoodsDetailDao{
private HibernateTemplate hibernateTemplate;
private Goodsdetail goodsdetail;
@Override
public int findGoods(Integer number) {
Session session = hibernateTemplate.getSessionFactory().getCurrentSession();
List paraList=new ArrayList<>();
StringBuffer sb=new StringBuffer("from Goodsdetail g where 1=1 ");
if(number!=null){
sb.append(" and g.number = ? ");
paraList.add(number);
}
Query query = session.createQuery(sb.toString());
for (int i = 0; i < paraList.size(); i++) {
query.setParameter(i, paraList.get(i));
}
List<Goodsdetail> list=query.list();
int totalCount=list.size();
return totalCount;
}
@Override
public List<Goodsdetail> limit(Integer number, int currentPage, int pageSize) {
Session session = hibernateTemplate.getSessionFactory().getCurrentSession();
List paraList=new ArrayList<>();
StringBuffer sb=new StringBuffer("from Goodsdetail g where 1=1 ");
if(number!=null){
sb.append(" and g.number = ? ");//这是精确查找,如果改成模糊匹配,把“=”改成like,然后add(‘%’+number+‘%’)
paraList.add(number);
}
Query query = session.createQuery(sb.toString());
for (int i = 0; i < paraList.size(); i++) {
query.setParameter(i, paraList.get(i));
}
List<Goodsdetail> list=query.setFirstResult((currentPage-1)*pageSize).setMaxResults(pageSize).list();//选择用hql语句进行分页
return list;
}
}
3.jsp页面
js函数:
function changesearch(currentPage){
$("#currentPage").val(currentPage);
$("#listform").action="goodsDetail_limit.action";//listform整个表单的名字,访问action中分页查询的方法
$("#listform").submit();
}
<form method="post" action="" id="listform">
<input type="hidden" value="${page.currentPage}" name="page.currentPage" id="currentPage">//设置隐藏域,将当前页的信息传递给action
</form>
<tr>
<td colspan="8"><div class="pagelist"><a href="javascript:changesearch(${page.firstPage})">首页</a>
<a href="javascript:changesearch(${page.prePage})">上一页</a>
${page.currentPage}
<a href="javascript:changesearch(${page.nextPage})">下一页</a>
<a href="javascript:changesearch(${page.lastPage})">尾页</a> </div></td>
</tr>
4.action中
省略set get方法和一些其他的属性,只写方法
public String limit(){
int pageSize=1;
int totalCount=goodsDetailService.findGoods(number);//Spring动态代理
if(page==null){
int currentPage=1;
list=goodsDetailService.limit(number, currentPage, pageSize);
page=new PageResult1(list, currentPage, pageSize, totalCount);
}else{
list=goodsDetailService.limit(number, page.getCurrentPage(), pageSize);
page=new PageResult1(list, page.getCurrentPage(), pageSize, totalCount);
}
return "ddd";
}
配置文件省略
SSH后台管理系统,实现查询+分页的更多相关文章
- phpcms v9后台多表查询分页代码
phpcms v9里面自带的listinfo分页函数蛮好用的,可惜啊.不支持多表查询并分页. 看了一下前台模板层支持get标签,支持多表查询,支持分页.刚好可以把这个功能搬到后台来使用. 我们现在对g ...
- ASP.NET MVC5+EF6+EasyUI 后台管理系统(1)-前言与目录(持续更新中...)
开发工具:VS2015(2012以上)+SQL2008R2以上数据库 您可以有偿获取一份最新源码联系QQ:729994997 价格 666RMB 升级后界面效果如下: 任务调度系统界面 http: ...
- 从零开始编写自己的C#框架(8)——后台管理系统功能设计
还是老规矩先吐下槽,在规范的开发过程中,这个时候应该是编写总体设计(概要设计)的时候,不过对于中小型项目来说,过于规范的遵守软件工程,编写太多文档也会拉长进度,一般会将它与详细设计合并到一起来处理,所 ...
- 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(48)-工作流设计-起草新申请
原文:构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(48)-工作流设计-起草新申请 系列目录 创建新表单之后,我们就可以起草申请了,申请按照严格的表单步骤和分 ...
- 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(37)-文章发布系统④-百万级数据和千万级数据简单测试
原文:构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(37)-文章发布系统④-百万级数据和千万级数据简单测试 系列目录 我想测试EF在一百万条数据下的显示时间! ...
- 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(22)-权限管理系统-模块导航制作
原文:构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(22)-权限管理系统-模块导航制作 最近比较忙,系统难度独步增加,文章的发布速度明显比以前慢了. 由于我们 ...
- 使用moy快速开发后台管理系统(一)
moy是什么? moy 是基于模型框架 kero 和 UI 框架 neoui 实现的应用框架,是前端集成解决方案,为企业级应用开发而生.github地址:iuap-design/tinper-moy ...
- vue重构后台管理系统调研
Q4要来了,我来这家公司已经一个季度了,通过对公司前端框架的整体认识,对业务的一些认识,发现,这些东西也都是可以重构,无论是v2,还是v3的代码. 首先就要那后台管理来开刀来,现有的技术框架就是php ...
- ASP.NET MVC5+EF6+EasyUI 后台管理系统(1)-前言与目录(转)
开发工具:VS2015(2012以上)+SQL2008R2以上数据库 您可以有偿获取一份最新源码联系QQ:729994997 价格 666RMB 升级后界面效果如下: 日程管理 http://ww ...
随机推荐
- 一起來玩鳥 Starling Framework(7)MovieClip
承上一篇,我們接著來講最後一個IAnimatable類別,MovieClip.Starling的MovieClip跟native的MovieClip不太一樣,它只能接收一個Vector.<Tex ...
- vim使用指北 ---- Multiple Windows in Vim
多窗口打开多个文件 vim -o file1 file2 ... ---- 默认上下分割窗口 vim -0n file1 file2 ... ---- vim默认会上下等分n个窗口 分割窗口 :[v] ...
- 倍福TwinCAT(贝福Beckhoff)常见问题(FAQ)-人机界面如何自动运行,不让用户干涉,设置起始界面
右击视图管理器,添加一个TargetVisualization 在起始视图中点击右边的按钮,然后选择一个HMI作为起始HMI 更多教学视频和资料下载,欢迎关注以下信息: 我的优酷空间: h ...
- Django—— 缓存框架
译者注:1.无用的,吹嘘的说辞不翻译:2.意译,很多地方不准确. 动态网站最为重要的一点就是好,网页是动态的.每一次用户请求页面,网站就要进行各种计算——从数据库查询,到render模板,到各种逻辑运 ...
- XML之Schema
前面学习了DTD.相同我们有了一套更完好的定义法则-Schema. 以下环绕Schema是什么.为何用以及怎么用谈谈自己的感受. XML Schema是基于XML的DTD替代者. XML Schema ...
- static_cast、dynamic_cast、const_cast和reinterpret_cast总结(转)
前言 这篇文章总结的是C++中的类型转换,这些小的知识点,有的时候,自己不是很注意,但是在实际开发中确实经常使用的.俗话说的好,不懂自己写的代码的程序员,不是好的程序员:如果一个程序员对于自己写的代码 ...
- C++中string.find()函数与string::npos
先说说string::npos参数: npos 是一个常数,用来表示不存在的位置,类型一般是std::container_type::size_type 许多容器都提供这个东西.取值由实现决定,一般是 ...
- 深入浅出理解之 onInterceptTouchEvent与onTouchEvent
参考:http://blog.csdn.net/android_tutor/article/details/7193090 与 http://www.cnblogs.com/kingcent/ ...
- Parallel小记
List<Temp> tList = new List<Temp>(); ; i < ; i++) { tList.Add(new Temp() { id = i, na ...
- 一个由正则表达式引发的血案 vs2017使用rdlc实现批量打印 vs2017使用rdlc [asp.net core 源码分析] 01 - Session SignalR sql for xml path用法 MemCahe C# 操作Excel图形——绘制、读取、隐藏、删除图形 IOC,DIP,DI,IoC容器
1. 血案由来 近期我在为Lazada卖家中心做一个自助注册的项目,其中的shop name校验规则较为复杂,要求:1. 英文字母大小写2. 数字3. 越南文4. 一些特殊字符,如“&”,“- ...