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.
 
 

60 lines
1.5 KiB

package com.example.datacollect; // 声明包名,与项目结构匹配
import java.util.Date; // 导入日期类,因为要用到Date类型
// Model层:只封装数据,无业务逻辑
public class Article {
// 原有字段
private String title; // 文章标题
private String content; // 文章内容
// 新增字段
private String author; // 文章作者
private Date publishDate; // 发布日期
// 1. 无参构造器(方便创建空对象)
public Article() {
}
// 2. 全参构造器(方便一次性赋值创建对象)
public Article(String title, String content, String author, Date publishDate) {
this.title = title;
this.content = content;
this.author = author;
this.publishDate = publishDate;
}
// 3. Getter/Setter方法(私有字段只能通过这些方法读写)
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
// 新增字段的get/set
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public Date getPublishDate() {
return publishDate;
}
public void setPublishDate(Date publishDate) {
this.publishDate = publishDate;
}
}