el表达式 分页 Struts2后台
2017-01-22 17:03
274 查看
效果图:
这边和上一篇使用的同一个分页写法,所以效果是一样的,只是后台有所不同,记录后台的写法而已,这篇的后台是ssh的框架,没什么重点,这次稍微记录的详细一点,顺便记录下搜索方法,只要下载一个js,下载地址:http://download.csdn.net/detail/qq_34117825/9743492,上干货:
jsp:
js:
struts.xml:
action :
home:
这边和上一篇使用的同一个分页写法,所以效果是一样的,只是后台有所不同,记录后台的写法而已,这篇的后台是ssh的框架,没什么重点,这次稍微记录的详细一点,顺便记录下搜索方法,只要下载一个js,下载地址:http://download.csdn.net/detail/qq_34117825/9743492,上干货:
jsp:
<div style="padding-top: 10px;"> <input type="hidden" id="basePath" value="<%=basePath%>"/> <input type="hidden" id="totalPage" value="${totalPage }"/> <input type="hidden" id="dqpageNo" value="${pageNo}"/> <button id="search" class="btn btn-primary">查询</button> <button id="reset" class="btn btn-primy">重置</button> </div>
<div class="pagema"> <b>共<a>${totalPage }</a>页</b> <b>当前为第<a>${pageNo}< 4000 ;/a>页</b> </div> <ul class="pagination pagination-centered" id="paginations"></ul>
js:
var bathPath=$("#basePath").val(); var totalPage=$("#totalPage").val(); /** 查询点击 */ $("#search").click(function(event) { /* Act on the event */ window.location.href = "findEquipmentInfo.action?equipmentInfo.deviceName=" + $("#search_equipment_name").val() + "&equipmentInfo.deviceIP=" + $("#search_equipment_ip").val() + "&equipmentInfo.deviceSN=" + $("#search_equipment_sn").val() + "&equipmentInfo.devicePN=" + $("#search_equipment_pn").val() + "&equipmentInfo.inTime=" + $("#input_date").val(); }); /** * 点击分页A标签事件 */ $("#paginations").on("click","li",function(){ var pageNo=$(this).find("a").text(); // var url=""+bathPath+"/njbh/company/getCompanyList.do?pageNo=pageNos&pageSize=10&companyName="+companyName; var url="findEquipmentInfo.action?pageNo=pageNos&pageSize=5"; if(pageNo=='...'){ return; }else{ showPage(pageNo,url,totalPage); } });
struts.xml:
<action name="findEquipmentInfo" class="equipmentInfoAction" method="findEquipmentInfo"> <result name="SUCCESS">/configurationmanagement-bs/configurationmanagement.jsp</result> </action>
action :
public String findEquipmentInfo(){ Integer pageNoNow= Integer.valueOf(pageNo) == null?1:Integer.valueOf(pageNo); Integer pageSizeNow= Integer.valueOf(pageSize) == null?5:Integer.valueOf(pageSize); //条件查询 分页 Page page = new Page(); page.setStart((pageNoNow-1)*pageSizeNow); page.setLimit(pageSizeNow); Map<String,Object> map=service.findEquipmentInfo_bs(equipmentInfo,page); List<EquipmentInfo> list = (List<EquipmentInfo>) map.get("list"); //查询总条数 Integer totalCount=(Integer) map.get("count"); //计算总页数 Integer totalPage=totalCount%pageSizeNow==0?totalCount/pageSizeNow:totalCount/pageSizeNow+1; ServletActionContext.getRequest().setAttribute("list", list); ServletActionContext.getRequest().setAttribute("totalPage", totalPage); ServletActionContext.getRequest().setAttribute("pageNo", pageNoNow); ServletActionContext.getRequest().setAttribute("pageSize", pageSizeNow); return SUCCESS; }
home:
public Map<String,Object> findEquipmentInfo_bs(EquipmentInfo equipmentInfo,Page page){ StringBuffer sbf =new StringBuffer("from EquipmentInfo"); if(null!=equipmentInfo){ sbf.append(" where 1=1 "); String deviceName=equipmentInfo.getDeviceName(); if(null!=deviceName&&!"".equals(deviceName)){ sbf.append(" and device_Name like '%"+deviceName+"%' "); } String deviceIP=equipmentInfo.getDeviceIP(); if(null!=deviceIP&&!"".equals(deviceIP)){ sbf.append(" and device_IP like '%"+deviceIP+"%' "); } String deviceSN=equipmentInfo.getDeviceSN(); if(null!=deviceSN&&!"".equals(deviceSN)){ sbf.append(" and device_SN like '%"+deviceSN+"%' "); } String devicePN=equipmentInfo.getDevicePN(); if(null!=devicePN&&!"".equals(devicePN)){ sbf.append(" and device_PN like '%"+devicePN+"%' "); } String inTime=equipmentInfo.getInTime(); if(null!=inTime&&!"".equals(inTime)){ sbf.append(" and in_Time like '%"+inTime+"%' "); } } Query query =sessionFactory.getCurrentSession().createQuery(sbf.toString()); if (null != page) { page.setTotalCount(count(sbf.toString(),true)); query.setFirstResult(page.getStart()); query.setMaxResults(page.getLimit()); } List<EquipmentInfo> list=query.list(); Map<String, Object> map=new HashMap<String, Object>(); map.put("list", list); map.put("count", page.getTotalCount()); return map; } private Integer count(String hql,boolean isHql) { int index = hql.indexOf("from"); hql = hql.substring(index); StringBuilder countHql = new StringBuilder("SELECT COUNT(*) "); countHql.append(hql); Query query; if(isHql){ query = this.sessionFactory.getCurrentSession().createQuery( countHql.toString()); }else{ query = this.sessionFactory.getCurrentSession().createSQLQuery( countHql.toString()); } List result = query.list(); if(isHql){ Long count = (Long) result.get(0); return count.intValue(); }else{ BigDecimal count = (BigDecimal) result.get(0); return count.intValue(); } }
相关文章推荐
- SSH学习(六)Struts2拦截器
- Java 中 byte、byte 数组和 int、long 之间的转换
- org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML doc
- sping 乱码
- Struts2实现文件上传和下载
- struts2 namespace
- java文件引用 提示包不存在
- java 爬虫
- 网页数据抓取之淘宝数据
- RxJava学习经验谈——map与flatmap
- spring学习笔记1
- Java 责任链模式
- Java getDeclared××× 方法和 get××× 方法的区别
- Java 8 flatMap example
- 操作系统课程设计 —— 模拟磁盘文件系统实现 (Java)
- spring security基础配置(一)
- java 等待所有线程执行完毕
- JAVA经典排序算法总结
- Spring+Struts2+hibernate快速使用
- HashMap实现原理分析