el表达式 分页 Struts2后台

7 篇文章 0 订阅
5 篇文章 0 订阅

效果图:

这边和上一篇使用的同一个分页写法,所以效果是一样的,只是后台有所不同,记录后台的写法而已,这篇的后台是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}</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();
		}
	}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值