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.
36 lines
1.3 KiB
36 lines
1.3 KiB
import java.time.LocalDate;
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
/**
|
|
* Model: 文章实体,只存放数据,无任何 I/O 代码
|
|
*/
|
|
public class Article {
|
|
private String title;
|
|
private String url;
|
|
private String content;
|
|
private String author; // 作业1:新增 author
|
|
private LocalDate publishDate; // 作业1:新增 publishDate
|
|
|
|
public Article(String title, String url, String content,
|
|
String author, LocalDate publishDate) {
|
|
this.title = title;
|
|
this.url = url;
|
|
this.content = content;
|
|
this.author = author;
|
|
this.publishDate = publishDate;
|
|
}
|
|
|
|
// ── getters ──
|
|
public String getTitle() { return title; }
|
|
public String getUrl() { return url; }
|
|
public String getContent() { return content; }
|
|
public String getAuthor() { return author; }
|
|
public LocalDate getPublishDate() { return publishDate; }
|
|
|
|
@Override
|
|
public String toString() {
|
|
String dateStr = (publishDate != null)
|
|
? publishDate.format(DateTimeFormatter.ISO_LOCAL_DATE) : "unknown";
|
|
return String.format("[%s] %s (by %s, %s)", url, title, author, dateStr);
|
|
}
|
|
}
|
|
|