spring data mongo模糊查询分页

野性酷女 2021-11-11 10:46 524阅读 0赞
  1. entity类

    // Document(collection = “radio_station”)对应mongo中的表名
    @Data
    @Document(collection = “radio_station”)
    public class RadioStation {

    1. @Id
    2. private String id;
    3. private String title;
    4. private String routeId;
    5. @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    6. private Date crateTime;
  2. interface类

    public interface RadioStationRepository extends MongoRepository {

    1. Page<RadioStation> findByTitleLike(String title, Pageable pageable);

    }

  3. server类

    // 根据相应字段模糊查询分页
    public Page findBytitle(String title, Integer page, Integer size){

    1. Pageable pageable = PageRequest.of(page - 1, size, new Sort(Sort.Direction.DESC,"id"));
    2. return radioStationRepository.findByTitleLike(title, pageable);

    }

发表评论

表情:
评论列表 (有 0 条评论,524人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Spring Data

    介绍 呈现更大的数据集可能具有挑战性。Spring Data可以通过提供各种分页功能来减轻一些痛苦。 基本 假设您要显示这样的分页组件: ![f3d8b7b18