- entity类
// Document(collection = "radio_station")对应mongo中的表名
@Data
@Document(collection = "radio_station")
public class RadioStation {
@Id
private String id;
private String title;
private String routeId;
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
private Date crateTime;
- interface类
public interface RadioStationRepository extends MongoRepository<RadioStation, String> {
Page<RadioStation> findByTitleLike(String title, Pageable pageable);
}
- server类
// 根据相应字段模糊查询分页
public Page<RadioStation> findBytitle(String title, Integer page, Integer size){
Pageable pageable = PageRequest.of(page - 1, size, new Sort(Sort.Direction.DESC,"id"));
return radioStationRepository.findByTitleLike(title, pageable);
}