From 174d69ea6d56048f6da401751d17f8ccd8eb32a4 Mon Sep 17 00:00:00 2001 From: Yuanruirui <3079566302@qq.com> Date: Wed, 13 May 2026 19:44:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?= =?UTF-8?q?=20'w9'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- w9/Article.java | 44 +++++++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/w9/Article.java b/w9/Article.java index f48d3e1..afdcb11 100644 --- a/w9/Article.java +++ b/w9/Article.java @@ -1,34 +1,56 @@ -package Article; +package com.example.datacollect.model; import java.time.LocalDate; +import java.time.format.DateTimeFormatter; public class Article { private String title; + private String url; private String content; - private String author; - private LocalDate publishDate; + private String author; // 新增:作者 + private LocalDate publishDate; // 新增:发布日期 - public Article(String title, String content, String author, LocalDate publishDate) { + public Article(String title, String url, String content) { + this(title, url, content, null, null); + } + + 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 and setters + // Getters and Setters public String getTitle() { return title; } - public String getContent() { return content; } - public String getAuthor() { return author; } - public LocalDate getPublishDate() { return publishDate; } - 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 String getAuthor() { return author; } public void setAuthor(String author) { this.author = author; } + + public LocalDate getPublishDate() { return publishDate; } public void setPublishDate(LocalDate publishDate) { this.publishDate = publishDate; } + // 可选:格式化日期字符串的便捷方法 + public String getFormattedPublishDate() { + if (publishDate == null) return "未知"; + return publishDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); + } + @Override public String toString() { - return String.format("Article{title='%s', author='%s', publishDate=%s}", - title, author, publishDate); + return "Article{" + + "title='" + title + '\'' + + ", url='" + url + '\'' + + ", author='" + author + '\'' + + ", publishDate=" + publishDate + + '}'; } } \ No newline at end of file