为其余api实现延迟表延迟加载

时间:2018-12-12 12:32:20

标签: java spring spring-boot spring-data-jpa spring-data

对于这些参数的惰性表加载,我需要实现Spring rest api端点:

export interface IPagination {
  current: number;
  next: number;
  previous: number;
  total: number;
  count: number;
}

我尝试实现此Java代码:

@GetMapping(value = "/page", params = { "current", "next", "previous", "total", "count"}, produces = "application/json")
    public Page<PaymentTransactionsDTO> findPaginated(@RequestParam("current") int current, @RequestParam("next") int next, 
            @RequestParam("previous") int previous, @RequestParam("total") int total,
            @RequestParam("count") int count) {

        Page<PaymentTransactionsDTO> resultPage = service.findPaginated(current ........);
        if (page > resultPage.getTotalPages()) {
            throw new MyResourceNotFoundException();
        }
        return resultPage;
    }

存储库:

@Override
    public List<PaymentTransactions> findAll(Specification<PaymentTransactions> spec) {
        String hql = "select e from " + PaymentTransactions.class.getName() + " e";
        TypedQuery<PaymentTransactions> query = entityManager.createQuery(hql, PaymentTransactions.class);
        List<PaymentTransactions> paymentTransactions = query.getResultList();
        return paymentTransactions;
    }

我使用的Crud资料库中必须使用Specification<PaymentTransactions> spec,您知道我必须如何使用spec才能解析值吗?还是有另一种方法可以进行正确的查询?

0 个答案:

没有答案