简体   繁体   English

如何在没有Spring数据的情况下使用Spring Page

[英]How to use spring Page without spring data

Hi i'm using below code for find article using spring with plain hibernate. 嗨,我正在使用下面的代码使用纯冬眠的spring查找文章。

public List<Article>  getArticles(int currPosition, int pageSize) {
        Criteria c = getSession().createCriteria(Article.class);
        c.addOrder(Order.desc("createdDate"));
        c.setFirstResult(currPosition);
        c.setMaxResults(pageSize);
        List<Article> result = c.list();
        return result;
    }

i'm not using spring data in my project now, So how can i use org.springframework.data.domain.Page with my project. 我现在不在我的项目中使用spring数据,所以如何在我的项目中使用org.springframework.data.domain.Page

Page<Person> persons = personService.findAllPageable(new PageRequest(evalPage, evalPageSize));

您可以使用Pageable#getSize来设置maxResultssetFirstResult Pageable#getOffset以及Pageable#getSort来获得排序参数。

You can even use pagerequest : 您甚至可以使用pagerequest:

public class PagePersons implements Serializable {
     private List<Persons> persons ;
     private int page ;
     private int numberPersons ;
     private int totalPersons ;
     private int totalPage ;

 //getters setters
}

and call your persons repository for exemple 并打电话给您的人员资料库

   public PagePersons getPagePersons(int codePerson, int page, int size) {
    Page<Person> Persons= personRepository.getPagePersons(codePerson, new PageRequest(page, size));

   PagePersons pagePersons =new PagePersons();
   pagePersons.setPersons(persons.getContent());
   pagePersons.setPage(page);
   pagePersons.setNumbrePersonss(persons.getNumberOfElements());
   pagePersons.setTotalPage(persons.getTotalPages());
   pagePersons.setPage(page);

    return  pagePersons ;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在没有 ObjectId 的情况下将 Mongo 与 Spring Data 一起使用 - How to use Mongo with Spring Data without ObjectId 如何在没有注释的情况下使用 Spring 数据 JDBC? - How to use Spring Data JDBC without annotations? 如何在没有配置的情况下将spring boot security用于自定义登录页面? - How to use spring boot security for custom login page without configuration? 如何使用没有登录页面的简单Spring Security AuthenticationProvider? - How to use a simple Spring Security AuthenticationProvider without logon page? 如何使用不带objectId的spring-data mongodb进行向上插入? - How to use spring-data mongodb without objectId to upsert? 如何配置Spring Data以在没有XML的Hibernate中使用Postgres? - How to configure Spring Data to use Postgres with Hibernate without XML? 没有事务的情况下如何使用Spring Data JPA? - How do you use Spring Data JPA without Transaction? 如何在没有_class属性的情况下使用带有couchbase的spring数据 - How to use spring data with couchbase without _class attribute 如何在没有spring boot java项目的情况下使用spring-data-redis - How to use spring-data-redis without spring boot java project 在没有 Spring Boot 应用程序的情况下使用 Spring Data JPA - Use Spring Data JPA without Spring Boot application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM