本文整理汇总了Java中org.hibernate.Criteria.setFirstResult方法的典型用法代码示例。如果您正苦于以下问题:Java Criteria.setFirstResult方法的具体用法?Java Criteria.setFirstResult怎么用?Java Criteria.setFirstResult使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.hibernate.Criteria
的用法示例。
在下文中一共展示了Criteria.setFirstResult方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: showBookByDynasty
import org.hibernate.Criteria; //导入方法依赖的package包/类
@Override
public Pager<Book> showBookByDynasty(String dynasty, int pageNo,int pageSize) {
System.out.println("-----执行到BookDaoImpl");
Session session = sessionFactory.getCurrentSession();
Criteria criteria = session.createCriteria(Book.class);
criteria.add(Restrictions.eq("dynasty", dynasty));
long recordTotal = ((Long) criteria.setProjection(Projections.rowCount()).uniqueResult()).longValue();
criteria.setProjection(null);
criteria.addOrder(Order.desc("clickTimes"));
criteria.setFirstResult((pageNo - 1) * pageSize);
criteria.setMaxResults(pageSize);
List<Book> results = criteria.list();
Pager<Book> page=new Pager<Book>(pageSize, pageNo, recordTotal, results);
return page;
}
示例2: getNewsInfoByConditionAndPage
import org.hibernate.Criteria; //导入方法依赖的package包/类
/**
* 根据条件查询指定新闻
*/
@Override
public List<?> getNewsInfoByConditionAndPage(NewsInfo condition, int page, int pageSize) {
Session session = SessionFactory.getCurrentSession();
Criteria criteria = session.createCriteria(NewsInfo.class);
if (condition != null) {
if (condition.getTopic() != null && condition.getTopic().getId() != null ) {
criteria.add(Restrictions.eq("topic.id", condition.getTopic().getId()));
}
if (condition.getTitle() != null && !"".equals(condition.getTitle())) {
criteria.add(Restrictions.like("title", condition.getTitle(), MatchMode.ANYWHERE));
}
}
criteria.setFirstResult(pageSize * (page - 1));
criteria.setMaxResults(pageSize);
criteria.addOrder(Order.desc("createDate"));
return criteria.list();
}
示例3: searchByTitle
import org.hibernate.Criteria; //导入方法依赖的package包/类
@Override
public Pager<Book> searchByTitle(String title, int pageNo, int pageSize) {
Session session = sessionFactory.getCurrentSession();
Criteria criteria = session.createCriteria(Book.class);
criteria.add(Restrictions.like("bookTitle", "%"+title+"%"));
long recordTotal = ((Long) criteria.setProjection(Projections.rowCount()).uniqueResult()).longValue();
criteria.setProjection(null);
// criteria.addOrder(Order.desc("clickTimes"));
criteria.setFirstResult((pageNo - 1) * pageSize);
criteria.setMaxResults(pageSize);
List<Book> results = criteria.list();
System.out.println(results.size()+"-------数据多少");
Pager<Book> page=new Pager<Book>(pageSize, pageNo, recordTotal, results);
return page;
}
示例4: findTopAppList
import org.hibernate.Criteria; //导入方法依赖的package包/类
@Override
public List<TopApp> findTopAppList(String keywords, Integer id, int page, int rows) {
Criteria cri = getSession().createCriteria(TopApp.class);
if (id != null && id > 0) {
cri.add(Restrictions.eq("id", id));
}
if (keywords != null && !keywords.isEmpty()) {
cri.add(Restrictions.like("name", keywords, MatchMode.ANYWHERE));
}
cri.add(Restrictions.and(Restrictions.ne("name",""), Restrictions.isNotNull("name")));
cri.addOrder(Order.desc("state"));
cri.setMaxResults(rows);
cri.setFirstResult(HibernateHelper.firstResult(page, rows));
List<TopApp> list = HibernateHelper.list(cri);
return list;
}
示例5: listUserByPage
import org.hibernate.Criteria; //导入方法依赖的package包/类
@Override
public Pager<User> listUserByPage(int pageNo, int pageSize) {
Session session = sessionFactory.getCurrentSession();
Criteria criteria = session.createCriteria(User.class);
long recordTotal = ((Long) criteria.setProjection(Projections.rowCount()).uniqueResult()).longValue();
criteria.setProjection(null);
criteria.addOrder(Order.desc("registerDate"));
criteria.setFirstResult((pageNo - 1) * pageSize);
criteria.setMaxResults(pageSize);
List<User> results = criteria.list();
return new Pager<User>(pageSize, pageNo, recordTotal, results);
}
示例6: doFindByExample
import org.hibernate.Criteria; //导入方法依赖的package包/类
public <T> List<T> doFindByExample(final String entityName, final T exampleEntity, final int firstResult,
final int maxResults) {
if (exampleEntity == null) {
throw new IllegalArgumentException("Example entity must not be null");
}
Criteria executableCriteria = (entityName != null ? getSession().createCriteria(entityName)
: getSession().createCriteria(exampleEntity.getClass()));
executableCriteria.add(Example.create(exampleEntity));
if (firstResult >= 0) {
executableCriteria.setFirstResult(firstResult);
}
if (maxResults > 0) {
executableCriteria.setMaxResults(maxResults);
}
return executableCriteria.list();
}
示例7: search
import org.hibernate.Criteria; //导入方法依赖的package包/类
@Override
public List<App> search(Short catalog, Integer subCatalog, int page, int rows, String keywords, String sort,
String order) {
Criteria cri = searchByFilter(catalog, subCatalog, keywords);
if (subCatalog != null) {
cri.add(Restrictions.eq("subCatalog", subCatalog));
}
// cri.addOrder(Order.asc("auditCatalog"));
if (sort != null && !sort.isEmpty()) {
HibernateHelper.addOrder(cri, sort, order);
} else {
if (order != null && "asc".equals(order)) {
cri.addOrder(Order.asc("downloads"));
} else {
cri.addOrder(Order.desc("downloads"));
}
}
if ("marketName".equals(sort)) {
cri.addOrder(Order.desc("downloads"));
}
// cri.addOrder(Order.asc("name"));
cri.setMaxResults(rows);
cri.setFirstResult(HibernateHelper.firstResult(page, rows));
List<App> list = HibernateHelper.list(cri);
return list;
}
示例8: search
import org.hibernate.Criteria; //导入方法依赖的package包/类
@Override
public List<MoViewTagApps> search(Integer tagId, Integer catalog, Short tagType, int page, int rows,
String keywords, String sort, String order) {
Criteria cri = searchByFilter(tagId, catalog, tagType, keywords);
if (sort != null && !sort.isEmpty()) {
HibernateHelper.addOrder(cri, sort, order);
} else {
if (order != null && "asc".equals(order)) {
cri.addOrder(Order.asc("id"));
} else {
cri.addOrder(Order.desc("id"));
}
}
cri.setMaxResults(rows);
cri.setFirstResult(HibernateHelper.firstResult(page, rows));
List<MoViewTagApps> list = HibernateHelper.list(cri);
return list;
}
示例9: setPageRequestToCriteria
import org.hibernate.Criteria; //导入方法依赖的package包/类
/**
* 设置分页参数到Criteria对象,辅助函数.
*/
protected Criteria setPageRequestToCriteria(final Criteria c, final PageRequest pageRequest) {
AssertUtils.isTrue(pageRequest.getPageSize() > 0, "Page Size must larger than zero");
c.setFirstResult(pageRequest.getOffset());
c.setMaxResults(pageRequest.getPageSize());
if (pageRequest.isOrderBySetted()) {
for (PageRequest.Sort sort : pageRequest.getSort()) {
if (PageRequest.Sort.ASC.equals(sort.getDir())) {
c.addOrder(Order.asc(sort.getProperty()));
} else {
c.addOrder(Order.desc(sort.getProperty()));
}
}
}
return c;
}
示例10: getForQuickTipsIndex
import org.hibernate.Criteria; //导入方法依赖的package包/类
@Override
public List<App> getForQuickTipsIndex(Session session, Integer currentPage, Integer pageSize) {
ProjectionList proList = Projections.projectionList();
proList.add(Projections.property("name"));
proList.add(Projections.property("downloadRank"));
proList.add(Projections.property("catalog"));
proList.add(Projections.property("id"));
Criteria cri = session.createCriteria(App.class);
cri.setProjection(proList);
cri.add(Restrictions.eq("hidden", false));
cri.addOrder(Order.asc("downloadRank"));
if (currentPage != null && pageSize != null) {
cri.setFirstResult(HibernateHelper.firstResult(currentPage, pageSize));
cri.setMaxResults(pageSize);
}
List<Object[]> list = HibernateHelper.list(cri);
List<App> apps = null;
if (list != null) {
apps = new ArrayList<App>(list.size());
for (Object[] obj : list) {
App e = new App();
e.setName((String) obj[0]);
e.setDownloadRank((Integer) obj[1]);
e.setCatalog((Short) obj[2]);
e.setId((Integer) obj[3]);
apps.add(e);
}
list.clear();
}
return apps;
}
示例11: search
import org.hibernate.Criteria; //导入方法依赖的package包/类
@Override
public List<MoFeatured> search(Short type, Boolean hidden, Boolean deleted, String keywords, int page, int rows,
String sort, String order) {
// 查询条件
Criteria cri = searchByFilter(type, hidden, deleted, keywords);
// 查询排序
searchSort(sort, order, cri);
cri.setMaxResults(rows);
cri.setFirstResult(HibernateHelper.firstResult(page, rows));
List<MoFeatured> list = HibernateHelper.list(cri);
return list;
}
示例12: searchByAuthor
import org.hibernate.Criteria; //导入方法依赖的package包/类
@Override
public Pager<Book> searchByAuthor(String author, int pageNo, int pageSize) {
Session session = sessionFactory.getCurrentSession();
Criteria criteria = session.createCriteria(Book.class);
criteria.add(Restrictions.like("authors", "%"+author+"%"));
long recordTotal = ((Long) criteria.setProjection(Projections.rowCount()).uniqueResult()).longValue();
criteria.setProjection(null);
// criteria.addOrder(Order.desc("clickTimes"));
criteria.setFirstResult((pageNo - 1) * pageSize);
criteria.setMaxResults(pageSize);
List<Book> results = criteria.list();
Pager<Book> page=new Pager<Book>(pageSize, pageNo, recordTotal, results);
return page;
}
示例13: showBookByClickTimes
import org.hibernate.Criteria; //导入方法依赖的package包/类
public Pager<Book> showBookByClickTimes(int pageNo, int pageSize) {
Session session = sessionFactory.getCurrentSession();
Criteria criteria = session.createCriteria(Book.class);
long recordTotal = ((Long) criteria.setProjection(Projections.rowCount()).uniqueResult()).longValue();
criteria.setProjection(null);
criteria.addOrder(Order.desc("clickTimes"));
criteria.setFirstResult((pageNo - 1) * pageSize);
criteria.setMaxResults(pageSize);
List<Book> results = criteria.list();
Pager<Book> page=new Pager<Book>(pageSize, pageNo, recordTotal, results);
return page;
}
示例14: listCollectsByUser
import org.hibernate.Criteria; //导入方法依赖的package包/类
@Override
public Pager<Collect> listCollectsByUser(int userId, int pageNo, int pageSize) {
Session session = sessionFactory.getCurrentSession();
Criteria criteria = session.createCriteria(Collect.class);
criteria.add(Restrictions.eq("userId", userId));
long recordTotal = ((Long) criteria.setProjection(Projections.rowCount()).uniqueResult()).longValue();
criteria.setProjection(null);
criteria.addOrder(Order.desc("collectDate"));
criteria.setFirstResult((pageNo - 1) * pageSize);
criteria.setMaxResults(pageSize);
List<Collect> results = criteria.list();
return new Pager<Collect>(pageSize, pageNo, recordTotal, results);
}
示例15: pageRoleByConditions
import org.hibernate.Criteria; //导入方法依赖的package包/类
public Pagination<RoleDO> pageRoleByConditions(Long pageIndex, Long pageSize, Map params) {
Criteria criteria = daoSupport.createCriteria(RoleDO.class);
criteria.add(Restrictions.eq("editEnable",Boolean.TRUE));
Long totalCount = (Long) criteria.setProjection(Projections.count("roleId")).uniqueResult();
criteria.setProjection(null);
criteria.setFirstResult((pageIndex.intValue() - 1) * pageSize.intValue());
criteria.setMaxResults(pageIndex.intValue()* pageSize.intValue());
List<RoleDO> items = criteria.list();
Pagination<RoleDO> pagination = new Pagination<RoleDO>(pageIndex, pageSize, totalCount);
pagination.setItems(items);
return pagination;
}