java吧 关注:1,253,302贴子:12,739,695
  • 10回复贴,共1

请问HQL模糊查询+分页怎么把参数传过去呢?

只看楼主收藏回复


怎么把params传过去呢?


1楼2013-11-30 17:28回复
    颜色看的眼疼 果断不看.....


    IP属地:广东2楼2013-11-30 17:53
    收起回复
      我一般是url传递


      IP属地:河南3楼2013-11-30 17:56
      回复
        没懂。。。


        4楼2013-11-30 19:47
        回复
          Criteria criteria = session.createCriteria(Room.class);
          if(xxxxxxxx){
          criteria.add(Restrictions.like(字段, “%字段值%”));
          }
          criteria.setResultTransformer(CriteriaSpecification.ROOT_ENTITY);
          criteria.setFirstResult((pageNumber-1)*pageSize);
          criteria.setMaxResults(pageSize);
          criteria.list();
          这里有些参考
          if (localFilter.getFilterType() == FilterType.gt&& StringUtils.isNotBlank(localFilter.getValue().toString())) {
          criteria.add(Restrictions.gt(localFilter.getProperty(), (Number) localFilter.getValue()));
          } else if (localFilter.getFilterType() == FilterType.lt&& StringUtils.isNotBlank(localFilter.getValue().toString())) {
          criteria.add(Restrictions.lt(localFilter.getProperty(), (Number) localFilter.getValue()));
          } else if (localFilter.getFilterType() == FilterType.ge&& StringUtils.isNotBlank(localFilter.getValue().toString())) {
          criteria.add(Restrictions.ge(localFilter.getProperty(), (Number) localFilter.getValue()));
          } else if (localFilter.getFilterType() == FilterType.le&& StringUtils.isNotBlank(localFilter.getValue().toString())) {
          criteria.add(Restrictions.le(localFilter.getProperty(), (Number) localFilter.getValue()));
          } else if (localFilter.getFilterType() == FilterType.like&& StringUtils.isNotBlank(localFilter.getValue().toString())) {
          criteria.add(Restrictions.like(localFilter.getProperty(), (String) localFilter.getValue() + "%"));
          } else if (localFilter.getFilterType() == FilterType.in&& StringUtils.isNotBlank(localFilter.getValue().toString())) {
          criteria.add(Restrictions.in(localFilter.getProperty(), new Object[] { localFilter.getValue() }));
          } else if (localFilter.getFilterType() == FilterType.isNull) {
          criteria.add(Restrictions.isNull(localFilter.getProperty()));
          } else if (localFilter.getFilterType() == FilterType.isNotNull) {
          criteria.add(Restrictions.isNotNull(localFilter.getProperty()));
          }


          IP属地:广东5楼2013-11-30 19:55
          收起回复
            咋搞定的?楼主赐教


            IP属地:上海来自Android客户端6楼2013-11-30 20:25
            收起回复
              public Collection<Room> getRoomByCondition(Room room,Integer pageno) {
              String hql="FROM Room r WHERE 1=1";
              if(StringUtils.isNotBlank(room.getRnumber())){
              hql=hql+" AND r.rnumber = '"+room.getRnumber()+"'";
              }
              if(StringUtils.isNotBlank(room.getIsvacant())){
              hql=hql+" AND r.isvacant = '"+room.getIsvacant()+"'";
              }
              if(StringUtils.isNotBlank(room.getVolum())){
              hql=hql+" AND r.volum like "+room.getVolum();
              }
              Query query=getHibernateTemplate().getSessionFactory().getCurrentSession().createQuery(hql);
              query.setFirstResult(pageno);
              query.setMaxResults(3);
              List<Room> result=query.list();
              return result;
              }


              7楼2013-11-30 21:03
              回复