开发者社区> 问答> 正文

SSH 怎么用hql实现分页

SSH 怎么用hql实现分页 急SSH 怎么用hql实现分页 急

展开
收起
云栖技术 2016-06-02 14:08:39 2388 0
1 条回答
写回答
取消 提交回答
  • 社区爱好者,专为云栖社区服务!
    /**
    * 查询分页
    */
    @Override
    public List query(final BizClaimVoucher bcv,
    final Integer curPage, final Integer pageSize, final SysEmployee emp) {
    List list = this.getHibernateTemplate().executeFind(
    new HibernateCallback() {
    
                    public Object doInHibernate(Session session)
                            throws HibernateException, SQLException {
                        String hql = "from BizClaimVoucher where 1=1";
                        if (emp != null) {
                            hql += "and sysEmployeess.name='" + emp.getName()
                                    + "'";
                        }
    
                        if (bcv != null) {
    
                            if (bcv.getStatus() != null
                                    && !bcv.getStatus().equals("全部")) {
                                hql += "and status ='" + bcv.getStatus() + "'";
                            }
    
                            if (bcv.getCreateTime() != null
                                    && bcv.getCreateTime().equals("")) {
                                hql += "and createTime>=to_date('"
                                        + bcv.getCreateTime()
                                        + "','YYYY-MM-DD HH24:MI:SS')";
                            }
    
                            if (bcv.getModifyTime() != null
                                    && bcv.getModifyTime().equals("")) {
                                hql += "and modifyTime<=to_date('"
                                        + bcv.getModifyTime()
                                        + "','YYYY-MM-DD HH24:MI:SS')";
                            }
    
                        }
    
                        Query query = null;
                        query = session.createQuery(hql);
                        query.setFirstResult((curPage - 1) * pageSize);
                        query.setMaxResults(pageSize);
    
                        return query.list();
                    }
    
                });
    
        return list;
    }
    **
    * 总记录条数
    */
    @Override
    public int selectCount(BizClaimVoucher bcv, SysEmployee emp) {
    int count = 0;
    try {
    String hql = "from BizClaimVoucher where 1=1";
    if (emp != null) {
    hql += "and sysEmployeess.name='" + emp.getName() + "'";
    }
    
            if (bcv != null) {
    
                if (bcv.getStatus() != null && !bcv.getStatus().equals("全部")) {
                    hql += "and status ='" + bcv.getStatus() + "'";
                }
    
                if (bcv.getCreateTime() != null
                        && bcv.getCreateTime().equals("")) {
                    hql += "and createTime>=to_date('" + bcv.getCreateTime()
                            + "','YYYY-MM-DD HH24:MI:SS')";
                }
    
                if (bcv.getModifyTime() != null
                        && bcv.getModifyTime().equals("")) {
                    hql += "and modifyTime<=to_date('" + bcv.getModifyTime()
                            + "','YYYY-MM-DD HH24:MI:SS')";
                }
    
            }
    
            List list = this.getHibernateTemplate().find(hql);
            if (list != null) {
                count = list.size();
            }
    
        } catch (Exception e) {
            e.printStackTrace();
        }
        return count;
    2019-07-17 19:24:48
    赞同 展开评论 打赏
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载