简体   繁体   English

Struts2 + Spring4 + Hibernate3分页

[英]Struts2 + Spring4 + Hibernate3 pagination

I'm developing a web application using MVC architectural pattern. 我正在使用MVC架构模式开发Web应用程序。

  • Struts2 (version 2.3.24) is used for the Business Logic and Presentation Layer Struts2(版本2.3.24)用于业务逻辑和表示层
  • Spring (version 4.1.0) is the dependency injection engine Spring(版本4.1.0)是依赖项注入引擎
  • Hibernate (version 3.6.10) is used for the Data Layer. 休眠(版本3.6.10)用于数据层。

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? 也许有JQueryAjax作为支持?

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);

    }
}

you can read more here 你可以在这里阅读更多

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

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