12. Springboot3+Vue3实现系统公告功能

285 字约 1 分钟读完4967 次阅读更新于 2026/5/3

创建系统公告表

CREATE TABLE `notice` (
  `id` int NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `title` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '公告标题',
  `content` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '公告内容',
  `time` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '发布时间',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='系统公告表';

公告首页渲染

时间线:https://element-plus-docs.bklab.cn/zh-CN/component/timeline.html

<div class="card" style="margin-top: 10px; width: 50%">
  <div style="font-size: 18px; margin-bottom: 20px">系统公告</div>
  <el-timeline style="max-width: 600px">
    <el-timeline-item :timestamp="item.time" color="#0bbd87" placement="top" v-for="item in data.noticeData">
      <h4>{{ item.title }}</h4>
      <p>{{ item.content }}</p>
    </el-timeline-item>
  </el-timeline>
</div>
const loadNotice = () => {
  request.get('/notice/selectAll').then(res => {
    if (res.code === '200') {
      data.noticeData = res.data
      if (data.noticeData.length > 3) {
        data.noticeData = data.noticeData.slice(0, 3)
      }
    } else {
      ElMessage.error(res.msg)
    }
  })
}
loadNotice()

小作业:

也可以尝试使用折叠面板来做系统公告的渲染

https://element-plus-docs.bklab.cn/zh-CN/component/collapse.html