zoukankan      html  css  js  c++  java
  • 在SSH框架下按条件分页查询

    这里是按照条件模糊查询要查找的内容

    在jsp页面:

    <table align="center" class="table-showboat" cellpadding="0" cellspacing="0">
            <tr>
                <td align="right" colspan="14" height="30">
                    <input type="text" name="bchaxun" id="bchaxun" onfocus="bfocuscha()" value="请输入船舶名">
                    <input type="button" value="查询" onclick="bclickcha()"><br>
                    <input type="radio" value="中文名" name="ming" id="zh" checked="checked">中文名
                    <input type="radio" value="英文名" name="ming" id="yi">英文名&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </td>
            </tr>
            <tr>
                <th class="boat-th" width="60">船员名</th>
                <th class="boat-th" width="60">船舶名</th>
                <th class="boat-th" width="70">违章代码</th>
                <th class="boat-th">违法行为</th>
                <th class="boat-th">违法依据</th>
                <th class="boat-th" width="35">记分</th>
                <th class="boat-th" width="70">罚款(元)</th>
                <th class="boat-th">行政处罚</th>
                <th class="boat-th" width="50">经办人</th>
                <th class="boat-th" width="70">事发时间</th>
                <th class="boat-th" width="60">事发地址</th>
                <th class="boat-th" width="60">事发原由</th>
                <th class="boat-th" width="60" style="border-right:1px solid #99BBE8;">操作</th>
            </tr>
            <s:if test="#request.mapbreak.num!=0">
                <s:iterator value="#request.mapbreak.list" var="break">
                    <tr align="center">
                        <td class="boat-td">${break.driveTable.sailorTable.sname }</td>
                        <td class="boat-td">${break.driveTable.boatTable.bchinesename }</td>
                        <td class="boat-td">${break.informationTable.incode }</td>
                        <td class="boat-td" align="left">${break.informationTable.inillegal }</td>
                        <td class="boat-td" align="left">${break.informationTable.inbasis }</td>
                        <td class="boat-td">${break.informationTable.ingrade }</td>
                        <td class="boat-td">${break.informationTable.inmoney }</td>
                        <td class="boat-td" align="left">${break.informationTable.inpunish }</td>
                        <td class="boat-td">${break.operatorTable.oname }</td>
                        <td class="boat-td">${break.vitime }</td>
                        <td class="boat-td">${break.viaddress }</td>
                        <td class="boat-td">${break.vireason }</td>
                        <td class="boat-td" style="border-right:#C5C5C5 1px solid;">
                            <a href="javascript:ubreak(${break.viid},'${break.driveTable.sailorTable.sname}','${break.driveTable.boatTable.bchinesename }','${break.driveTable.bfirst}','${break.driveTable.bcheck}','${break.informationTable.incode }','${break.informationTable.inillegal }','${break.informationTable.inbasis }','${break.informationTable.ingrade }',${break.informationTable.inmoney },'${break.informationTable.inpunish }','${break.operatorTable.oname }','${break.vitime }','${break.viaddress }','${break.vireason }',${mapbreak.page })">修改</a>
                            <a href="break!delOneBreak.do?viid=${break.viid }" onclick="return(confirm('真的要删除吗?'))">删除</a>
                        </td>
                    </tr>
                </s:iterator>
                <!-- 分页 -->
                <tr align="right">
                    <td colspan="13">
                        <font style="font-size:12px; color:black;">当前${mapbreak.page}页     共${mapbreak.count}页,${mapbreak.num}条</font>
                        <a href="break!getAllBreak.do?page=1">【首  页】</a>
                        <a href="break!getAllBreak.do?page=${mapbreak.page-1}">【上一页】</a>
                        <a href="break!getAllBreak.do?page=${mapbreak.page+1}">【下一页】</a>
                        <a href="break!getAllBreak.do?page=${mapbreak.count}">【末  页】</a>
                        <a href="break!getAllBreak.do">【返回初始页】</a>
                    </td>
                </tr>
            </s:if>
            <s:if test="#request.mapbreak.num==0">
                <tr height="100" valign="middle">
                    <td colspan="14" align="center"><font size="14">对不起,没有您想要的结果!</font></td>
                </tr>
                <tr>
                    <td colspan="14" align="right"><a href="break!getAllBreak.do">【返回初始页】</a></td>
                </tr>
            </s:if>
        </table>

    js代码:

    var bcha=document.getElementById("bchaxun");
        function bfocuscha(){
            bcha.value="";
        }
        function bclickcha(){
            var bxun=bcha.value;
            if(document.getElementById("zh").checked){
                location="break!getAllBreak.do?bname="+bxun+"&flag=zh";
                return;
            }
            if(document.getElementById("yi").checked){
                location="break!getAllBreak.do?bname="+bxun+"&flag=en";
                return;
            }
        }

    在dao包中,如果模糊查询的条件不是外键的情况:

        /*条件查询分页显示*/
        public List checkPageQuery(final String hql, final Integer page , final Integer size, final Object ...p){
            return getHibernateTemplate().executeFind(new HibernateCallback(){
    
                public Object doInHibernate(Session session)
                        throws HibernateException, SQLException {
                    Query query = session.createQuery(hql);
                    if (p != null) {
                        for (int i = 0; i < p.length; i++) {
                            query.setParameter(i, p[i]);
                        }
                    }
                    if ( page != null && size != null) {
                        query.setFirstResult((page-1)*size).setMaxResults(size);
                    }
                    List list = query.list();
                    return query.list();
                }});
        }
        //求按条件查询的船舶的总条数
        public Integer countcBoat(final String bname, final String flag) {
            return (Integer) getHibernateTemplate().execute(new HibernateCallback(){
    
                public Object doInHibernate(Session session)
                        throws HibernateException, SQLException {
                    String hql = "select count(*) from BoatTable where 1=1";
                    StringBuffer sb=new StringBuffer(hql);
                    if(bname!="" && bname!=null && "en".equals(flag)){
                        sb.append(" and benglishname like '%"+bname+"%'");
                    }
                    if(bname!="" && bname!=null && "ch".equals(flag)){
                        sb.append(" and bchinesename like '%"+bname+"%'");
                    }
                    String sql=sb.toString();
                    Query query = session.createQuery(sql);
                    Object object = query.uniqueResult();
                    return Integer.parseInt(object.toString());
                }});
        }
    
    
        public String getHQL(final String bname, final String flag) {
            String hql="from BoatTable where 1=1";
            StringBuffer sb=new StringBuffer(hql);
            if(bname!="" && bname!=null && "en".equals(flag)){
                sb.append(" and benglishname like '%"+bname+"%'");
            }
            if(bname!="" && bname!=null && "ch".equals(flag)){
                sb.append(" and bchinesename like '%"+bname+"%'");
            }
            sb.append(" order by bid desc");
            String sql=sb.toString();
            return sql;
        }

    在dao包下面,如果模糊查询的条件是外键的情况:

        //分页显示所有船舶违章的具体信息
        public List getAllBreakInformation(final String hql, final Integer page , final Integer size, final Object ...p){
            return getHibernateTemplate().executeFind(new HibernateCallback(){
    
                public Object doInHibernate(Session session)
                        throws HibernateException, SQLException {
                    Query query = session.createQuery(hql);
                    if (p != null) {
                        for (int i = 0; i < p.length; i++) {
                            query.setParameter(i, p[i]);
                        }
                    }
                    if ( page != null && size != null) {
                        query.setFirstResult((page-1)*size).setMaxResults(size);
                    }
                    List<ViolationTable> list = query.list();
                    SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
                    String string;
                    Date vitime;
                    for (ViolationTable object : list) {
                        string=sdf.format(object.getVitime());
                        vitime=java.sql.Date.valueOf(string);
                        object.setVitime(vitime);
                    }
                    return list;
                }});
        }
        
        //求船舶违章记录的总条数
        public Integer countBoatBreak(final String bname,final String flag) {
            return (Integer) getHibernateTemplate().execute(new HibernateCallback(){
    
                public Object doInHibernate(Session session)
                        throws HibernateException, SQLException {
                    String hql = "select count(*) from ViolationTable where 1=1";
                    StringBuffer sb=new StringBuffer(hql);
                    if(bname!="" && bname!=null && "en".equals(flag)){
                        sb.append(" and driveTable.boatTable.benglishname like '%"+bname+"%'");
                    }
                    if(bname!="" && bname!=null && "zh".equals(flag)){
                        sb.append(" and driveTable.boatTable.bchinesename like '%"+bname+"%'");
                    }
                    String sql=sb.toString();
                    Query query = session.createQuery(sql);
                    Object object = query.uniqueResult();
                    return Integer.parseInt(object.toString());
                }});
        }
        
        public String getHQL(final String bname,final String flag) {
            String hql="from ViolationTable where 1=1";
            StringBuffer sb=new StringBuffer(hql);
            if(bname!="" && bname!=null && "en".equals(flag)){
                sb.append(" and driveTable.boatTable.benglishname like '%"+bname+"%'");
            }
            if(bname!="" && bname!=null && "zh".equals(flag)){
                sb.append(" and driveTable.boatTable.bchinesename like '%"+bname+"%'");
            }
            sb.append(" order by viid desc");
            String sql=sb.toString();
            return sql;
        }

    在service下面:

    //分页显示所有船舶违章信息
        public Map getAllBreak(String bname,String flag,int page,int size){    
            String hql=violationDao.getHQL(bname, flag);
            System.out.println("hql="+hql);
            //求总条数
            int num = violationDao.countBoatBreak(bname, flag);
            System.out.println("num="+num);
            
            //求总页数
            int count = num%size==0 ? num/size : num/size+1 ;
            
            //越界查询
            if(page<1)   page = 1;
            if(page>count)  page = count ;
            
            List list = violationDao.getAllBreakInformation(hql, page, size);
            
            Map map = new HashMap();
            
            map.put("list", list);
            map.put("page", page);
            map.put("size", size);
            map.put("num", num);
            map.put("count", count);
            
            return map;
        }

    在action下面:

        //分页查询所有船舶违章信息
        public String getAllBreak(){
            HttpServletRequest request=ServletActionContext.getRequest();
            HttpServletResponse response=ServletActionContext.getResponse();
            int page =1 ;
            int size = 5 ;
            String pageString = request.getParameter("page");
            if (pageString != null) 
                page = Integer.parseInt(pageString);
            
            String sizeString = request.getParameter("size");
            if(sizeString != null)
                size = Integer.parseInt(sizeString);
            String bname=request.getParameter("bname");
            System.out.println("bname="+bname);
            String flag=request.getParameter("flag");
            System.out.println("flag="+flag);
            
            Map map = breakService.getAllBreak(bname, flag, page, size);
            request.setAttribute("mapbreak", map);
            List operator=breakService.findAllOpe();
            request.setAttribute("operator", operator);
            List infor=breakService.findAllInfor();
            request.setAttribute("information", infor);
            return "ShowBreak";
        }
  • 相关阅读:
    数据挖掘实践(9):基础理论(九)数学基础(九)概率(五)⻉叶斯公式
    数据挖掘实践(8):基础理论(八)数学基础(八)概率(四)参数估计(二)
    数据挖掘实践(7):基础理论(七)数学基础(七)概率(三)参数估计(一)
    数据挖掘实践(6):基础理论(六)数学基础(六)概率(二)随机变量
    Linux上快速入门英特尔Optane DC Persistent Memory Module的配置与使用
    ovs 流表
    Cannot get thread event message: debugger service failed
    gdb ovs
    rror while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
    glibc
  • 原文地址:https://www.cnblogs.com/xinxinjava/p/3200675.html
Copyright © 2011-2022 走看看