boycod3 boycod3 - 1 month ago 13
Java Question

How to use spring Page without spring data

Hi i'm using below code for find article using spring with plain hibernate.

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.

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

Answer

You can use Pageable#getSize to set maxResults, Pageable#getOffset for setFirstResult and Pageable#getSort to obtain sorting parameters.