zoukankan      html  css  js  c++  java
  • [Java Spring MVC] Paging and sorting DTOs

    Repo:

    package com.example.ec.repo;
    
    import com.example.ec.domain.TourRating;
    import com.example.ec.domain.TourRatingPk;
    import org.springframework.data.domain.Page;
    import org.springframework.data.domain.Pageable;
    import org.springframework.data.repository.CrudRepository;
    import org.springframework.data.rest.core.annotation.RepositoryRestResource;
    
    import java.util.List;
    import java.util.Optional;
    
    @RepositoryRestResource(exported = false)
    public interface TourRatingRepository extends CrudRepository<TourRating, TourRatingPk> {
        List<TourRating> findByPkTourId(Integer tourId);
    
        Optional<TourRating> findByPkTourIdAndPkCustomerId(Integer tourId, Integer customerId);
    
        Page<TourRating> findByPkTourId(Integer tourId, Pageable pageable);
    }

    Controller:

        @GetMapping
        public Page<RatingDto> getAllRatingsForTour(@PathVariable(value = "tourId") int tourId, Pageable pageable) {
            verifyTour(tourId);
            Page<TourRating> ratings = tourRatingRepository.findByPkTourId(tourId, pageable);
            return new PageImpl<>(
                    ratings.get()
                        .map(RatingDto::new)
                        .collect(Collectors.toList()),
                    pageable,
                    ratings.getTotalElements()
            );
        }

  • 相关阅读:
    双线性过滤
    textureView
    cubemap
    selfshadow
    cbuffer padding
    异常
    Python深浅拷贝
    数据类型分类
    集合类型内置方法
    字典数据类型内置方法
  • 原文地址:https://www.cnblogs.com/Answer1215/p/14141933.html
Copyright © 2011-2022 走看看