动力节点王鹤SpringBoot3笔记——第八章 文章管理模块

目录

第八章  文章管理模块

8.1  配置文件 

8.2 视图文件

8.3 Java代码


第八章  文章管理模块

创建新的Spring Boot项目,综合运用视频中的知识点,做一个文章管理的后台应用。 新的Spring Boot项目Lession20-BlogAdmin。Maven构建工具,包名称com.bjpowernode.blog JDK19,依赖:

  • Spring Web
  • Lombok
  • Thymeleaf
  • MyBatis Framework
  • MySQL Driver

依赖还需要Bean Validation 需求:文章管理工作,发布新文章,编辑文章,查看文章内容等 

8.1  配置文件 

组织配置文件 

 app-base.yml

article:
  #最低文章阅读数量
  low-read: 10
  #首页显示最多的文章数量
  top-read: 20

db.yml

spring:
  datasource:
    type: com.zaxxer.hikari.HikariDataSource
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/blog?serverTimezone=Asia/Shanghai
    username: root
    password: 123456
    hikari:
      auto-commit: true
      maximum-pool-size: 10
      minimum-idle: 10
      #获取连接时,检测语句
      connection-test-query: select 1
      connection-timeout: 20000
      #其他属性
      data-source-properties:
        cachePrepStmts: true
        dataSource.cachePrepStmtst: true
        dataSource.prepStmtCacheSize: 250
        dataSource.prepStmtCacheSqlLimit: 2048
        dataSource.useServerPrepStmts: true

8.2 视图文件

logo文件
favicon.ico放在static/ 根目录下

创建模板页面 

 articleList.html

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="UTF-8">
  <title>文章列表</title>
  <link rel="icon" href="../favicon.ico" type="image/x-icon"/>
  <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
</head>
<body>
  <div style="margin-left: 200px">
    <h3>阅读最多的前10篇文章</h3>
    <table  border="1px"  cellspacing="0px" cellpadding="2px">
      <thead>
        <th>选择</th>
        <th>序号</th>
        <th>标题</th>
        <th>副标题</th>
        <th>已读数量</th>
        <th>发布时间</th>
        <th>最后修改时间</th>
        <th>编辑</th>
      </thead>
      <tbody>
        <tr th:each="article,loopStats : ${articleList}">
          <td><input type="checkbox" th:value="${article.id}"></td>
          <td th:text="${loopStats.index+1}"></td>
          <td th:text="${article.title}"></td>
          <td th:text="${article.summary}"></td>
          <td th:text="${article.readCount}"></td>
          <td th:text="${article.createTime}"></td>
          <td th:text="${article.updateTime}"></td>
          <td>
            <a th:href="@{/article/get(id=${article.id})}">编辑</a>
          </td>
        </tr>
        <tr>
          <td colspan="8">
            <table width="100%">
              <tr>
                <td><button id="add" onclick="addArticle()">发布新文章</button></td>
                <td><button id="delete" onclick="deleteArticle()">删除文章</button></td>
                <td><button id="read" onclick="readOverview()">文章概览</button></td>
              </tr>
            </table>
          </td>
        </tr>
      </tbody>
    </table>
    <form id="frm" th:action="@{/view/addArticle}" method="get">
    </form>

    <form id="delfrm" th:action="@{/article/removeArticle}" method="post">
      <input type="hidden" id="idsDom" name="ids" value="" >
    </form>
  </div>
  <script type="text/javascript">

    function addArticle(){
      $("
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值