java - Spring MVC pagination and sorting -
i trying implement pagination , sorting in spring mvc. per understanding, can use pagingandsortingrepository or jparepository same(http://springinpractice.com/2012/05/11/pagination-and-sorting-with-spring-data-jpa).
but both these use default findall method so.
i wish create own method , execute custom query , perform pagination sorting on that(lets search category name , sort creation date). not sure how using pagingandsortingrepository or jparepository.
it great if can have sort of guidance achieve this.
thanks in advance.
with jpa can many combination of queries specifying method signatures. please consult http://docs.spring.io/spring-data/jpa/docs/1.4.3.release/reference/html/jpa.repositories.html
in repository interface can
list<person> findall(); // standard list<person> findbyid(string id); // looking person have specific id list<person> findbynamelike(string name); // can put name "foo%"
if want pagination , sorting...
page<person> findbynamelike(string name, pagerequest pagerequest);
and use like
int page = 0; // first page int size = 10; // show 10 result max per page page personpage = repo.findbynamelike("a%", new pagerequest(page,size,sort.direction.asc, "birthdate")); // pagination person name, page 0, 10 item per page, , sorted person.birthdate.
good luck
Comments
Post a Comment