个人博客系统

一、技术选型

  • 后端:springboot + mybatis-plus + thymeleaf2
  • 数据库:mysql
  • 前端UI:semantic

二、项目构建

1、maven依赖

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.it</groupId>
    <artifactId>blog</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>blog</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.4.1</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid-spring-boot-starter</artifactId>
            <version>1.1.17</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-aop</artifactId>
        </dependency>

        <!--StringUtils-->
        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.6</version>
        </dependency>

        <dependency>
            <groupId>com.atlassian.commonmark</groupId>
            <artifactId>commonmark</artifactId>
            <version>0.10.0</version>
        </dependency>
        <dependency>
            <groupId>com.atlassian.commonmark</groupId>
            <artifactId>commonmark-ext-heading-anchor</artifactId>
            <version>0.10.0</version>
        </dependency>
        <dependency>
            <groupId>com.atlassian.commonmark</groupId>
            <artifactId>commonmark-ext-gfm-tables</artifactId>
            <version>0.10.0</version>
        </dependency>
    </dependencies>


    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

2、项目配置application.yml

spring:
  thymeleaf:
    mode: HTML
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    username: root
    url: jdbc:mysql://localhost:3306/my_blog?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=UTC
    password: 12345
  mvc:
    static-path-pattern: /static/**
  messages:
    basename: i18n/messages


# 开启日志
logging:
  level:
    com.it.blog: debug

# mybatis-plus配置
mybatis-plus:
  type-aliases-package: com.it.blog.entity
  global-config:
    db-config:
      id-type: auto
  configuration:
    lazy-loading-enabled: true
    aggressive-lazy-loading: false

server:
  port: 80

说明:项目开启了全局懒加载,以便减少数据库压力

3、项目结构
在这里插入图片描述
说明
(1)、utils包存放一些常用的工具类
(2)、resources下的i18n目录存放用于国际化的文件

三、数据库设计

项目共设计了六张表,每张表的字段有相应的注释,博客类型和标签均是选自菜鸟教程
1、t_user表用于保存用户数据
在这里插入图片描述
2、t_blog表用于保存博客数据
在这里插入图片描述
3、t_type表用于保存博客类型
在这里插入图片描述

4、t_tag表用于保存博客标签
在这里插入图片描述
5、t_blogs_tags表用于保存博客和标签的归属关系
在这里插入图片描述
6、t_comment表用于保存评论数据
在这里插入图片描述
说明:
在多对多数据关系中,要建立一张中间表用于查询数据,在t_blog表中增加了tag_ids字段,是一个id列表所组成的字符串如:2,4,6,然后查询一对多的数据就可以直接访问这个字段,不必再去浏览中间表,减少了数据库的压力。虽然加了这个字段,但也保存了中间表,方便后续统计

四、具体实现举例

mybatis-plus单表动态sql

    private Map<String, Object> getBlogMap(BlogEntity blogEntity) {
        Map<String, Object> map = new HashMap<>();
        map.put("type_id", blogEntity.getTypeId());
        map.put("recommend", blogEntity.getRecommend());
        return map;
    }

    private Wrapper<BlogEntity> getBlogWrapper(BlogEntity blogEntity) {
        QueryWrapper<BlogEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(blogEntity.getTitle() != null && !"".equals(blogEntity.getTitle()), "title", blogEntity.getTitle());
        queryWrapper.allEq(this.getBlogMap(blogEntity), false);
        return queryWrapper;
    }

说明:
(1)、allEq(Map<R, V> params, boolean null2IsNull)
params : key为数据库字段名,value为字段值
null2IsNull : 为true则在map的value为null时调用 isNull 方法,为false时则忽略value为null的
(2)、like(boolean condition, R column, Object val)
condition为条件,只有满足条件才查询

五、最终效果

1、首页
在这里插入图片描述
2、分类页
在这里插入图片描述
3、标签页
在这里插入图片描述
4、归档页
在这里插入图片描述
5、后台博客管理页
在这里插入图片描述
6、后台分类管理页
在这里插入图片描述

7、后台标签管理页
在这里插入图片描述

  • 4
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值