spring-data-mongo实现spring整合mongodb

本文介绍了如何使用Spring Data MongoDB将Spring Boot应用与MongoDB数据库进行整合,包括Maven配置、应用配置文件设置以及实体映射的详细步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用spring-data-mongo整合spring和mongodb

1.maven配置

  <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-mongodb</artifactId>
        </dependency>

2.配置文件

spring:
  data:
    mongodb:
      uri: mongodb://mongcent:b7tLPM#asd@192.168.1.158:27017/tnaot

3.实体映射

@Setter
@Getter
@Builder
@Document(collection="video_tag_time_mapping")//集合名
public class VideoTagTimeMapping {

    @Id
    private Long _id;

    /**
     * 语言
     */
    private Integer lang;

    /**
     * 内容标签
     */
    private List<Integer> contentTagList;

    /**
     * 是否热门
     */
    private Boolean isHot;

    /*
     * 作者id
     */
    private Long authorId;


    /**
     * 是否原创
     */
    private Boolean isOriginal;

    /**
     * 结束时间
     */
    private Date endTime;

    /*
     * 时效
     */
    private Integer tagTime;

    /**
     * 因子
     */
    private Double factor;


    /**
     * 时效值
     */
    private Float timeIndex;

    /**
     * 热度值
     */
    private Double hotIndex;

    /**
     * 时效更新时间
     */
    private Date timeIndexUpdateTime;

    /**
     * 热度更新时间
     */
    private Date hotIndexUpdateTime;


    /**
     * 发布时间
     */
    private Date releaseTime;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 1、爬虫;2、后台;3、自媒体;4、普通用户
     */
    private Integer sourceType;


    private Long releaseTimeStamp;


}
public interface VideoTagTimeMappingRepository extends MongoRepository<VideoTagTimeMapping, Long>{

    Page<VideoTagTimeMapping> findByEndTimeGreaterThan(Date endTime, Pageable pageable);

    @Query(fields = "{'_id':1, 'sourceType':1, 'timeIndex':1,'authorId':1}")
    Page<VideoTagTimeMapping> findByLangAndTimeIndexGreaterThan(Integer lang,Float timeIndex,Pageable pageable);

    @Query(fields = "{'_id':1, 'sourceType':1, 'hotIndex':1,'authorId':1 }")
    Page<VideoTagTimeMapping> findByLangAndTimeIndexGreaterThanAndHotIndexGreaterThan(Integer lang,Float timeIndex,
                                                                                      Float hotIndex,Pageable pageable);

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值