一个搜索框,然后会获取大量信息,将信息进行分页,每一页显示固定条数。

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后台管理系统,实现查询+分页的更多相关文章

  1. phpcms v9后台多表查询分页代码

    phpcms v9里面自带的listinfo分页函数蛮好用的,可惜啊.不支持多表查询并分页. 看了一下前台模板层支持get标签,支持多表查询,支持分页.刚好可以把这个功能搬到后台来使用. 我们现在对g ...

  2. ASP.NET MVC5+EF6+EasyUI 后台管理系统(1)-前言与目录(持续更新中...)

    开发工具:VS2015(2012以上)+SQL2008R2以上数据库  您可以有偿获取一份最新源码联系QQ:729994997 价格 666RMB  升级后界面效果如下: 任务调度系统界面 http: ...

  3. 从零开始编写自己的C#框架(8)——后台管理系统功能设计

    还是老规矩先吐下槽,在规范的开发过程中,这个时候应该是编写总体设计(概要设计)的时候,不过对于中小型项目来说,过于规范的遵守软件工程,编写太多文档也会拉长进度,一般会将它与详细设计合并到一起来处理,所 ...

  4. 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(48)-工作流设计-起草新申请

    原文:构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(48)-工作流设计-起草新申请 系列目录 创建新表单之后,我们就可以起草申请了,申请按照严格的表单步骤和分 ...

  5. 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(37)-文章发布系统④-百万级数据和千万级数据简单测试

    原文:构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(37)-文章发布系统④-百万级数据和千万级数据简单测试 系列目录 我想测试EF在一百万条数据下的显示时间! ...

  6. 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(22)-权限管理系统-模块导航制作

    原文:构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(22)-权限管理系统-模块导航制作 最近比较忙,系统难度独步增加,文章的发布速度明显比以前慢了. 由于我们 ...

  7. 使用moy快速开发后台管理系统(一)

    moy是什么? moy 是基于模型框架 kero 和 UI 框架 neoui 实现的应用框架,是前端集成解决方案,为企业级应用开发而生.github地址:iuap-design/tinper-moy ...

  8. vue重构后台管理系统调研

    Q4要来了,我来这家公司已经一个季度了,通过对公司前端框架的整体认识,对业务的一些认识,发现,这些东西也都是可以重构,无论是v2,还是v3的代码. 首先就要那后台管理来开刀来,现有的技术框架就是php ...

  9. ASP.NET MVC5+EF6+EasyUI 后台管理系统(1)-前言与目录(转)

    开发工具:VS2015(2012以上)+SQL2008R2以上数据库 您可以有偿获取一份最新源码联系QQ:729994997 价格 666RMB 升级后界面效果如下: 日程管理   http://ww ...

随机推荐

  1. 报错:numRecords must not be negative

    报错的原因:删除已经使用过的kafka topic,然后新建同名topic 解决方法:把topic名字换一下 (有其他更好的解决方法,可以不修改topic名)

  2. POJ 3077-Rounders(水题乱搞)

    Rounders Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7697   Accepted: 4984 Descript ...

  3. [加入用户]解决useradd 用户后没有加入用户Home文件夹的情况,Linux改变文件或文件夹的訪问权限命令,linux改动用户password,usermod的ysuum安装包。飞

    usermod的yum安装包: shadow-utils 将nobody用户加入到nogroup 组: usermod -g nogroup nobody cat /etc/passwd|grep n ...

  4. spring中使用 @value 简化配置文件的读取

    1.在applicationContext.xml文件中配置properties文件 <bean id="propertyConfigurer" class="or ...

  5. UVA 11534 - Say Goodbye to Tic-Tac-Toe(博弈sg函数)

    UVA 11534 - Say Goodbye to Tic-Tac-Toe 题目链接 题意:给定一个序列,轮流放XO,要求不能有连续的XX或OO.最后一个放的人赢.问谁赢 思路:sg函数.每一段.. ...

  6. Intellij IDEA + Tomcat 出现 HTTP status 404错误的解决办法

    最近要做POC,接了个老项目改,使用war exploded部署到本机的Tomcat(8.5版) 通过Intellij IDEA启动Tomcat的时候发现系统的登录页面出现HTTP-status-40 ...

  7. STM32F103RB, KEIL编译出错:cannot open preprocessing output output file &quot;.\神舟i号\main.d&quot; no such file or

    STM32F103RB,   KEIL编译出错:cannot open preprocessing output output file ".\神舟i号\main.d" no su ...

  8. JSON——Java中的使用

    1. 构建JSON方法(数据——>JSON) 这里使用Maven构建项目 在pom.xml中添加如下依赖 <dependency> <groupId>org.json&l ...

  9. RIP协议

    1.概念:RIP协议是一种内部网关协议(IGP),是一种动态路由选择协议,用于自治系统(AS)内的路由信息的传递.        RIP协议基于距离矢量算法(DistanceVectorAlgorit ...

  10. wxPython 4.0.0b2安装

    https://www.cnblogs.com/NanShan2016/p/5518235.html 亮的界面是一个GUI程序必不可少的一部分,wxPython可以做到这一点,加之Python强大的功 ...