实体对应的图片列表分页

Action里方法:

public  String  list(){


        HttpServletRequest request = ServletActionContext.getRequest();
        /*
        Integer showtype = 1;
        try {
            String type  = request.getParameter("showtype");
            if(type!=null&&!type.equals("")){
                showtype = Integer.valueOf(type);
            }
        } catch (NumberFormatException e) {
            e.printStackTrace();
            showtype = 1;
        }
        Integer unitId = null;
        String uid = request.getParameter("unitId");
        if(uid!=null&&!uid.equalsIgnoreCase("")){
            unitId = Integer.valueOf(uid);
        }*/

        request.setAttribute("unitId", unitId);
        request.setAttribute("showtype", showtype);
       //pager
        int offset = 0;
        try {
            String po = request.getParameter("pager.offset");
            if (po == null) {
                offset = 0;
            } else {
                offset = Integer.parseInt(po);
            }
        } catch (NumberFormatException e) {
            offset = 0;
        }
        int pageSize = 10;
       
        PagerModel pm = adminImageService.getKangarooImgByUnitId(unitId, showtype, offset, pageSize);
        int totalPages = 0;
        if(pm.getTotal()%pageSize==0){
            totalPages = pm.getTotal()/pageSize;
        }else{
            totalPages = pm.getTotal()/pageSize+1;
        }
        request.setAttribute("pageSize", pageSize);
        request.setAttribute("totalPages", totalPages);
        request.setAttribute("pm", pm);
        //分页结束
       
        if(showtype.intValue()==1){
            return "listimages";
        }else if(showtype.intValue()==2){
            return "listvideos";
        }else if(showtype.intValue()==3){
            return "listQimages";
        }else if(showtype.intValue()==4){
            return "listeyes";
        }
        return "listimages";

     }

//-----------------Service 调用 DAO里的方法

Dao里的方法:

public PagerModel pageModel(final String hql,final Object[] params,final int offset,
        final int pagesize) {
        //int total = 11;
        //String countHql = getCountHql(hql);
        try {
        return (PagerModel) this.getHibernateTemplate().execute(new HibernateCallback(){
            @SuppressWarnings("unchecked")
            public Object doInHibernate(Session s)
            throws HibernateException, SQLException {
                int total = 0;
                String countHql=null;
                if(hql.indexOf("distinct")!=-1){
                    countHql = getCountHqlOther(hql);
                }else{
                    countHql = getCountHql(hql);
                }
               
                Query countQuery = s.createQuery(countHql);
                if (params != null && params.length > 0) {
                    for (int i = 0; i < params.length; i++) {
                        countQuery.setParameter(i, params[i]);
                    }
                }
                total = ((Integer) countQuery.uniqueResult()).intValue();
                Query query = s.createQuery(hql);
                if (params != null && params.length > 0) {
                    for (int i = 0; i < params.length; i++) {
                        query.setParameter(i, params[i]);
                    }
                }
                query.setFirstResult(offset);
                query.setMaxResults(pagesize);
                List datas = query.list();
                PagerModel pm = new PagerModel();
                pm.setTotal(total);
                pm.setDatas(datas);
                return pm;
            }
           
        });
        } catch (RuntimeException e) {
            logger.error("分页查询异常,HQL:" + hql, e);e.printStackTrace();
            throw e;
        }

}

//----------jsp 读取PM数据  

<%@ page language="java" pageEncoding="GBK" import="java.util.*"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="pg"  uri="http://jsptags.com/tags/navigation/pager" %>
function upLoadImage(){
        var myimage = document.getElementById("image");
        var v_point = myimage.value.lastIndexOf(".");
        var v_type = myimage.value.substr(v_point).toUpperCase();
        if(myimage.value!=""){//
            //alert(v_type);
            if(v_type!=".JPG"&&v_type!=".JPEG"&&v_type!=".GIF"&&v_type!=".BMP"&&v_type!=".PNG"){
               // alert("该文件类型不允许上传。请上传.jpg|.jpeg|.gif|.bmp|.png|类型的文件");
                myimage.outerHTML=myimage.outerHTML;
                return false;
            }
        }
           if(document.upImageForm.pic.value==""){
              alert("请选择上传图片!");
              document.upImageForm.pic.focus();
               return false;
        }
       
        var weight =document.getElementById('weight');
        var weightValue = trim(weight.value);
        weight.value = trim(weight.value);
        if(weightValue==null||weightValue==''){
            alert('请填写权重值!');
            weight.focus();
            return false;
        }else if(!isNum(weightValue)){
            alert('权重值要为数字');
            weight.focus();
            return false;
        }
       
        var sb = document.getElementById("sb");
        sb.value="上传中....请稍等";
        sb.disabled="disabled";
        return true;
      }     

var pop_up_form='<div id="qvjing">'
+'  <ul id="gongyong">'
+"    <li><a href='#nogo' οnclick='openDiv(/"/kangaroo/admin/adminImage!list.dhtml?unitId=${requestScope.unitId}&showtype=1&d=<%= Math.random() %>/")' class='hei12'>图片</a></li>"
+"    <li><a href='#nogo' οnclick='openDiv(/"/kangaroo/admin/adminImage!list.dhtml?unitId=${requestScope.unitId}&showtype=2&d=<%= Math.random() %>/")' class='hei12'>视频</a></li>"
+'  </ul>'
+'</div>'
+'<div id="jianli_geren">'
+'<form action="<%=request.getContextPath() %>/admin/adminImage!upImage.dhtml" method="post" enctype="multipart/form-data" target="Ihidden" name="upImageForm" id="upImageForm" οnsubmit="return upLoadImage();">'
+'  <table width="95%" border="0" cellspacing="0" cellpadding="0">'
+'    <tr>'
+'      <td class="jianli_left">'
+'      <div id="jianli_list"> '
+'          <ul id="jianli_content">'
+'            <li>'
+'              <h1>*</h1>'
+'              上传图片:'
+'              <input class="jl_input2" id="image" name="pic" type="file" οnchange="return CheckExt(this);"/>'
+'              <div id="ltor">只能上传*.jpg,*.gif,*.bmp类型的文件.</div>'
+'              <input type="hidden" id="unitId" name="unitId" value="${requestScope.unitId}"/>'
+'              <input type="hidden" id="showtype" name="showtype" value="1"/>'
+'            </li>'
+'            <li>'
+'              <h1>*</h1>'
+'              设置权重:'
+'              <input id="weight" name="weight" type="text" style="width:50px;height:18px;"/>&nbsp;&nbsp;<font color="red">只能是数字</font>'
+'            </li>'
+'          </ul>'
+'        </div>'
+'        <div id="submit">'
+'          <input class="submit_button" type="submit" value="上 传 图 片" id="sb" name="sb"/>'
+"                    <input type='button' name='cancel' value='关闭' οnclick='javascript:top.city2_map.city2_map.closeOrDelHot2(/"unitimagelistdiv/");'>"
+'        </div>'
+'        </td>'
+'     </tr>'
+'  </table>'

+'   <div class="gallery">'
+'       <c:forEach items="${requestScope.pm.datas}" var="image" varStatus="vs">'
+'         <ul id="onfo_pic_small">'
+'                  <li >'
+'                   <a href="${image.path}" target="_blank" rel="lightbox[roadtrip]" ><img src="${image.imagePath}" width="80px" height="70px" id="img_${vs.count}" border="0"/></a></li>'
+'                 <li><a href="javascript://" οnclick="top.main.delimageDiv(${image.id},${requestScope.unitId})">删除</a>'
+'                 &nbsp;&nbsp;&nbsp;'               
+'                 <input type="text" id="weight_${image.id}" name="weight_${image.id }" value="${image.weight }" style="width:30px;"/>&nbsp;<input type="button" name="修改" value="修改" οnclick="setWeight(${image.id});" style="height: 20px;width:40px;"/>'
+'                 </li>'
+'      </ul>'
+'       </c:forEach>'  
+'   </div>'
+'   <br/><br/><br/>'
+'   <div class="fanye">'
+'         <c:if test="${!empty requestScope.pm.datas}" var="isEmpty"><ul>'
+'     <li>共${requestScope.pm.total}条信息 '
+'         每页${requestScope.pageSize }条信息 '
+'         共${requestScope.totalPages }页</li>'
+'     <li>'
+'         <c:choose><c:when test="${requestScope.pm.total gt 0}"><pg:pager url="/kangaroo/admin/adminImage!list.dhtml" items="${requestScope.pm.total}" export="currentPageNumber=pageNumber" maxIndexPages="10" isOffset="true" maxPageItems="${requestScope.pageSize}"><pg:param name="unitId" value="${unitId}"/><pg:param name="showtype" value="1"/><pg:pages><c:choose><c:when test="${currentPageNumber eq pageNumber }"><font color="red">${pageNumber }</font></c:when><c:otherwise><a href="#" οnclick="dofenyedd(${pageNumber })" class="redd"><input type="hidden" id="${pageNumber }" value="${pageUrl}">${pageNumber }</a></c:otherwise></c:choose></pg:pages></pg:pager></c:when></c:choose>'
+'     </li>'
+'     </ul>'
+'     </c:if>'
+'     <c:if test="${!isEmpty}">'
+'         没有数据!'
+'     </c:if>'
+'    </div>'                   
+'<br />'
+'<br />'
+'<br/>'
+'</div>'
+'  </form>'

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值