使用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);
}