spring data mongo模糊查询分页
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
ss")
private Date crateTime;
interface类
public interface RadioStationRepository extends MongoRepository
{ Page<RadioStation> findByTitleLike(String title, Pageable pageable);
}
server类
// 根据相应字段模糊查询分页
public PagefindBytitle(String title, Integer page, Integer size){ Pageable pageable = PageRequest.of(page - 1, size, new Sort(Sort.Direction.DESC,"id"));
return radioStationRepository.findByTitleLike(title, pageable);
}
还没有评论,来说两句吧...