精通系列)

Posted 北芳科技

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了精通系列)相关的知识,希望对你有一定的参考价值。

Java 之 Spring Boot + Vue + Element UI 前后端分离项目(上-项目搭建) 【博客论坛项目高仿CSDN】(一篇文章精通系列)

一、项目简介

1、JDK1.8 SpringBoot 2.6.2 mybatis2.2.0
2. Vue3
3. 使用工具 后端IDEA 和 前端HBuilderX
4、数据库使用mysql5.5 SQL文件

SQL文件下载
https://download.csdn.net/download/qq_44757034/80926009

二、后端SpringBoot项目搭建

1、项目搭建

(1)创建工程



(2)引入依赖

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>cn.itbluebox</groupId>
    <artifactId>springboot_csdn</artifactId>
    <version>1.0-SNAPSHOT</version>
    <name>springboot_csdn</name>
    <description>Demo project for Spring Boot</description>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.6.2</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.2.0</version>
        </dependency>
        <!--分页插件 -->
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <version>1.4.1</version>
        </dependency>
        <!-- 通用Mapper启动器 -->
        <dependency>
            <groupId>tk.mybatis</groupId>
            <artifactId>mapper-spring-boot-starter</artifactId>
            <version>2.0.3</version>
        </dependency>
        <!-- mysql驱动 -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.32</version>
        </dependency>
        <dependency>
            <groupId>tk.mybatis</groupId>
            <artifactId>mapper-spring-boot-starter</artifactId>
            <version>2.0.3</version>
        </dependency>
        <dependency>
            <groupId>tk.mybatis</groupId>
            <artifactId>mapper-core</artifactId>
            <version>1.0.4</version>
        </dependency>
        <dependency>
            <groupId>tk.mybatis</groupId>
            <artifactId>mapper-extra</artifactId>
            <version>1.0.4</version>
        </dependency>
        <dependency>
            <groupId>tk.mybatis</groupId>
            <artifactId>mapper-base</artifactId>
            <version>1.0.4</version>
        </dependency>
        <!-- web启动器 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.62</version>
        </dependency>

        <dependency>
            <groupId>com.github.tobato</groupId>
            <artifactId>fastdfs-client</artifactId>
            <version>1.26.1-RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
        </dependency>
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt</artifactId>
            <version>0.9.0</version>
        </dependency>
        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time</artifactId>
            <version>2.9.9</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>
    </dependencies>
    <build>
        <resources>
            <!--注册Dao包目录下Mybatis映射文件资源目录-->
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
            </resource>
            <!--注册webapp目录为资源目录-->
            <resource>
                <directory>src/main/webapp</directory>
                <targetPath>META-INF/resources</targetPath>
                <includes>
                    <include>**/*.*</include>
                </includes>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

(3)创建其他项目文件以及配置文件

1)启动类



package cn.itbluebox.springbootcsdn;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SpringBootCSDNApplication 
    public static void main(String[] args) 
        SpringApplication.run(SpringBootCSDNApplication.class, args);
    


2)配置文件

application.yml

server:
  port: 9090
#datasource
spring:
  datasource:
    url: jdbc:mysql:///csdn
    username: root
    password: root
    driver-class-name: com.mysql.jdbc.Driver
  mvc:
    view:
      prefix: /
      suffix: .jsp
mybatis:
  configuration:
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
sc:
  jwt:
    secret: blueboxai@Login(Auth*^31)&heiMa% # 登录校验的密钥
    pubKeyPath: C:\\\\Users\\\\ZHENG\\\\Desktop\\\\leyou_msgrs\\\\rsa\\\\rsa.pub # 公钥地址
    priKeyPath: C:\\\\Users\\\\ZHENG\\\\Desktop\\\\leyou_msgrs\\\\rsa\\\\rsa.pri # 私钥地址
    expire: 30 # 过期时间,单位分钟
    cookieName: SC_TOKEN
    cookieMaxAge: 1200

3)webapp


设置文件类型

4)创建完整的目录结构


创建方式都一样省略不写

运行测试

运行成功,工程搭建的没有问题

2、编写数据库对应的实体类

(1)Blog

package cn.itbluebox.springbootcsdn.domain;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.Transient;
import java.util.Date;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Blog 
    private Long id;              //文章id
    private String title;         //文章标题
    private String abstract_text;       //文章内容
    private String thumbnail;       //缩略图
    private Date create_time;      //创建时间
    private Long like_count;              //点赞数量
    private Long view_count;     //浏览量
    private Long consumer_id;     //用户ID
    private String type_id;       //类型
    private Long blog_article_id;     //博客文章ID
    @Transient //Transient声明当前字段不是数据对应的字段
    private Long[] typeId;


(2)BlogArticle

package cn.itbluebox.springbootcsdn.domain;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.Table;
import java.util.Date;
@Data
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "blog_article")
public class BlogArticle 

    private Long id;
    private String context;
    private Date last_update_time;      //更新时间
    private Character is_original;



(2)BlogHeader

package cn.itbluebox.springbootcsdn.domain;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.Table;
import javax.persistence.Transient;
@Data
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "blog_header")
public class BlogHeader 
    private Long id;
    private Long blog_id;
    private String title;
    private String abstract_text;
    private String type;
    @Transient //Transient声明当前字段不是数据对应的字段
    private String thumbnail;


(3)BlogType

package cn.itbluebox.springbootcsdn.domain;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.Table;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "blog_type")
public class BlogType 
    private Long id;
    private String typename;


(4)Consumer

package cn.itbluebox.springbootcsdn.domain;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.Table;
import javax.persistence.Transient;
import java.util.Date;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "consumer")
public class Consumer 
    private Long id;
    private Character sex;
    private String name;
    private String email;
    private String image;
    private String type;
    private Long phone;
    private Date birthday;
    private String password;
    @Transient //Transient声明当前字段不是数据对应的字段
    private String token;


3、编写枚举类ExceptionEnum

精通系列)上

Oracle 从入门到精通系列讲解 - 总目录

Oracle 从入门到精通系列讲解 - 总目录

精通系列)

Filecoin系列 - 基准测试工具

OpenCV | OpenCV实战从入门到精通系列四 --常用函数讲解