0

我很难理解如何检索页面中的信息,而不是整体。到目前为止,我当前的应用程序有一个数据库、一个服务器/服务和一个前端 GUI 客户端应用程序。

后端(服务)如下所示:

IOrdheadService.java

public interface IOrdheadService {

@GET
@Path("/ordheads")
@Produces("application/json")
List<Ordhead> getOrdheadList();

@GET
@Path("/ordhead/{id}")
@Produces("application/json")
Ordhead getOrdhead(@PathParam("id") String id);

OrdheadService.java

@Service
@Path("ordheadservice")
public class OrdheadService implements IOrdheadService {

@Autowired
private OrdheadRepository ordheadRepository;
@Autowired
private IPrimaryKeyGenerator primaryKeyGenerator;

@Override
public List<Ordhead> getOrdheadList() {
    return ordheadRepository.findAll();
}

@Override
public Ordhead getOrdhead(@QueryParam("id") String id) {
    return ordheadRepository.findByPrimaryKey(id);
}

OrdheadRepository.java

public interface OrdheadRepository extends JpaRepository<Ordhead, String> {

Ordhead findByPrimaryKey(String id);
}

客户端收到如下信息:

    private List<Ordhead> resultList;
    resultList = client.getOrdheadList();

然后我使用 |< << >> >| 遍历 resultList 屏幕上的按钮。

尝试使用页面复制该功能,我在 OrdheadService 中尝试了以下操作

    PageRequest page1 = new PageRequest(
            0, 20, Direction.ASC, "primaryKey");
           Pageable p = new PageRequest(0, 20);
    return ordheadRepository.findAll(page1).getContent();

哪个有效 - 返回前 20 个结果。但是,我需要让客户知道有多少页。这样,如果有 40 条记录并且客户端在记录 20 上,按>>按钮将获取接下来的 20 条记录并将客户端移动到记录 21。

我试图阅读以下链接:

https://github.com/SpringSource/spring-data-rest/wiki/Paging-and-Sorting http://blog.fawnanddoug.com/2012/05/pagination-with-spring-mvc-spring-data.html

但还没有弄清楚如何正确实施它。

任何帮助表示赞赏。

谢谢你

4

1 回答 1

1

ordheadRepository.findAll(page1)返回一个Page<Ordhead>包含所有必要信息以及页面内容的 a。

于 2013-07-05T21:01:57.770 回答