简体   繁体   中英

Struts2 + Spring4 + Hibernate3 pagination

I'm developing a web application using MVC architectural pattern.

  • Struts2 (version 2.3.24) is used for the Business Logic and Presentation Layer
  • Spring (version 4.1.0) is the dependency injection engine
  • Hibernate (version 3.6.10) is used for the Data Layer.

I have to create a PaginationFactory class that I can dynamically use for the various section of the application. I've several examples on google and StackOverflow... But mostly old stuff like this question .

Any ideas on how implement this function with using something more modern? Maybe with JQuery and Ajax as support?

I suggest for you to use Spring Data Jpa, it's already have implemented pagination.

Your repository will look like this:

public interface MedicamentRepository extends JpaRepository<Medicament, Integer> {}

You can extend, as example, PagingAndSortingRepository interface, if you don't need some of methods that JpaRepository provides.

public class SomeClass{

@Autowired
public MedicamentRepository medicamentRepo; 

 public void someMethod(){
//in spring data jpa, page count starts from 0; 
 PageRequest pageRequest = new PageRequest(pageNumber, 
pageSize); //also have sorting

org.springframework.data.domain.Page<Medicament> page = medicamentRepo.findAll(pageRequest);

    }
}

you can read more here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM