发布文章系统 Spring boot 搭建个人博客系统(四)——文章的发布和分页显示
![](http://419ai.oss-cn-beijing.aliyuncs.com/2023/07/20230726191152761.png)
Spring boot 搭建个人博客系统(四)——文章的发布和分页显示 一直想用Spring boot 搭建一个属于自己的博客系统,刚好前段时间学习了叶神的牛客项目课受益匪浅
一直想用 boot 搭建一个属于自己的博客系统,刚好前段时间学习了叶神的牛客项目课受益匪浅,乘热打铁也主要是学习,好让自己熟悉这类项目开发的基本流程。系统采用 boot++MySQL的框架进行项目开发。
项目源码:Jblog
个人主页:’s page
原文地址: boot 搭建个人博客系统(四)——文章的发布和分页显示
0. 思路 1. 数据模型
文章的发布和显示功能需要操作数据库中的表,使用作为系统的ORM框架用来简化数据操作。
public class Article {
private int id;
private String title;
private String describes;
private String content;
private Date createdDate;
private int commentCount;
private String category;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescribes() {
return describes;
}
public void setDescribes(String describes) {
this.describes = describes;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public Date getCreatedDate() {
return createdDate;
}
public void setCreatedDate(Date createdDate) {
this.createdDate = createdDate;
}
public int getCommentCount() {
return commentCount;
}
public void setCommentCount(int commentCount) {
this.commentCount = commentCount;
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
}
@Mapper
public interface ArticleDao {
String TABLE_NAEM = " article ";
String INSERT_FIELDS = " title, describes, content, created_Date, comment_Count, category ";
String SELECT_FIELDS = " id, " + INSERT_FIELDS;
@Insert({
"insert into",TABLE_NAEM,"(",INSERT_FIELDS,") values (#{title},#{describes},#{content}" +
",#{createdDate},#{commentCount},#{category})"})
int insertArticle(Article article);
@Select({
"select",SELECT_FIELDS,"from",TABLE_NAEM,"where id=#{id}"})
Article selectById(int id);
@Select({
"select",SELECT_FIELDS,"from",TABLE_NAEM,"order by id desc limit #{offset},#{limit}"})
List selectLatestArticles(@Param("offset") int offset, @Param("limit") int limit);
@Select({
![](http://419ai.oss-cn-beijing.aliyuncs.com/2023/07/20230726191152761.png)