[英]Struts2 + Spring4 + Hibernate3 pagination
I'm developing a web application using MVC architectural pattern. 我正在使用MVC架构模式开发Web应用程序。
I have to create a PaginationFactory
class that I can dynamically use for the various section of the application. 我必须创建一个PaginationFactory
类,该类可以动态用于应用程序的各个部分。 I've several examples on google and StackOverflow... But mostly old stuff like this question . 我在google和StackOverflow上有几个示例...但是大多数都是旧的东西,例如这个问题 。
Any ideas on how implement this function with using something more modern? 关于如何使用更现代的方法实现此功能的任何想法? Maybe with JQuery
and Ajax
as support? 也许有JQuery
和Ajax
作为支持?
I suggest for you to use Spring Data Jpa, it's already have implemented pagination. 我建议您使用Spring Data Jpa,它已经实现了分页。
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. 例如,如果不需要JpaRepository提供的某些方法,则可以扩展PagingAndSortingRepository接口。
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);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.