mashiguang

小马快跑

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  20 随笔 :: 0 文章 :: 60 评论 :: 0 Trackbacks
public PageModel<CrmWarning> query(PageModel<CrmWarning> pageModel)
            
throws Exception {
        Assert.notNull(pageModel);
        
        DetachedCriteria dc 
= DetachedCriteria.forClass(CrmWarning.class);
        
        
/*
         * 添加查询条件
         * 如:dc.add(Restrictions.like("key", "%"+pageModel.getCondition("key")+"%"));
         * 
         * 
*/
        
if (null != pageModel.getCondition("warnLevel")) {
            dc.add(Restrictions.eq(
"warnLevel", pageModel.getCondition("warnLevel")));
        }
        
if (StringUtils.isNotBlank((String)pageModel.getCondition("detail"))) {
            dc.add(Restrictions.like(
"detail""%"+pageModel.getCondition("detail")+"%"));
        }
        
if (StringUtils.isNotBlank((String)pageModel.getCondition("warnDate"))) {
            
/*
             * warnDate格式是yyyy-MM-dd,这里改成查询这一天的预警
             * Restrictions.sqlRestriction()允许写原生sql的方式完成特殊需求,如下
             * 
*/
            dc.add(Restrictions.sqlRestriction(
"to_char(time_start,'yyyy-MM-dd') = '" + pageModel.getCondition("warnDate"+ "'"));
        }
        
if (null != pageModel.getCondition("templateId")) {
            
/*
             * 这里的templateId是模板的主键id,查询时应该转换成模板对象
             * 
*/
            CrmWarnTemplate warnTemplate 
= new CrmWarnTemplate();
            warnTemplate.setTemplateId((Long)pageModel.getCondition(
"templateId"));
            dc.add(Restrictions.eq(
"crmWarnTemplate", warnTemplate));
        }
        
        dc.addOrder(Order.asc(
"crmWarnTemplate"));
        dc.addOrder(Order.desc(
"timeStart"));
        
        pageModel.setDateList(warningDao.query(dc, pageModel.getFirstNote(), pageModel.getNumInPage()));
        pageModel.setTotal(warningDao.count(dc));
        
        
return pageModel;
    }
posted on 2011-08-11 22:50 mashiguang 阅读(419) 评论(0)  编辑  收藏 所属分类: 示例代码