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()));
}