You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.7 KiB
51 lines
1.7 KiB
package com.example.datacollect.model;
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
public class Article {
|
|
private String title;
|
|
private String url;
|
|
private String content;
|
|
private LocalDateTime crawledAt; // 新增:抓取时间
|
|
|
|
// 构造函数自动初始化抓取时间
|
|
public Article(String title, String url, String content) {
|
|
this.title = title;
|
|
this.url = url;
|
|
this.content = content;
|
|
this.crawledAt = LocalDateTime.now();
|
|
}
|
|
|
|
// Getter & Setter
|
|
public String getTitle() { return title; }
|
|
public void setTitle(String title) { this.title = title; }
|
|
public String getUrl() { return url; }
|
|
public void setUrl(String url) { this.url = url; }
|
|
public String getContent() { return content; }
|
|
public void setContent(String content) { this.content = content; }
|
|
public LocalDateTime getCrawledAt() { return crawledAt; }
|
|
public void setCrawledAt(LocalDateTime crawledAt) { this.crawledAt = crawledAt; }
|
|
|
|
// 重写equals/hashCode:基于URL判断唯一性(增量抓取核心)
|
|
@Override
|
|
public boolean equals(Object o) {
|
|
if (this == o) return true;
|
|
if (o == null || getClass() != o.getClass()) return false;
|
|
Article article = (Article) o;
|
|
return url != null ? url.equals(article.url) : article.url == null;
|
|
}
|
|
|
|
@Override
|
|
public int hashCode() {
|
|
return url != null ? url.hashCode() : 0;
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
return "Article{" +
|
|
"title='" + title + '\'' +
|
|
", url='" + url + '\'' +
|
|
", crawledAt=" + crawledAt + // 新增字段到日志输出
|
|
'}';
|
|
}
|
|
}
|
|
|