硅谷项目,由尚硅谷分享,具体项目视频可以根据B站尚硅谷进行学习。搭建项目可以直接根据Spring Boot进行获取,本次主要是个人的的一些分析操作
后面代码主要以分析为主,相关内容不会的,可以观看尚硅谷视频
一、下载配套相关文件
文件可以根据尚硅谷公众号进行获取
二、 搭建后台环境
2.1 相关要求
- jdk:1.8版本
- springboot:3版本以下
2.2 后台架构模块
- guigu-oa-parent:根目录,管理子模块:
- common:公共类模块
- common-util:核心工具类
- service-util:serice模块工具类
- spring-security:spring-security业务模块
- model:实体类模块
- service-oa:系统服务模块
- common:公共类模块
2.3 开始搭建
1. 搭建父工程:guiigu-oa-parent
- 由于需要指定springboot版本,直接使用springboot进行搭建,注意jdk为1.8
2. 生成相关model
- 相关model结构
- 使用最普通的model进行生成,不需要使用springboot
2.4 搭建依赖关系
1. guigu-oa-parent父模块管理依赖版本
<?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.7.13</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.gdhd</groupId>
<artifactId>guigu-oa-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>guigu-oa-parent</name>
<description>guigu-oa-parent</description>
<modules>
<module>common</module>
<module>common/common-util</module>
<module>common/service-util</module>
<module>common/spirng-security</module>
<module>model</module>
<module>service-oa</module>
</modules>
<properties>
<java.version>1.8</java.version>
<mybatis-plus.version>3.4.1</mybatis-plus.version>
<mysql.version>8.0.30</mysql.version>
<knife4j.version>3.0.3</knife4j.version>
<jwt.version>0.9.1</jwt.version>
<fastjson.version>2.0.21</fastjson.version>
</properties>
<dependencyManagement>
<dependencies>
<!--mybatis-plus 持久层-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>${mybatis-plus.version}</version>
</dependency>
<!--mysql-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
<!--knife4j-->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>${knife4j.version}</version>
</dependency>
<!--jjwt-->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>${jwt.version}</version>
</dependency>
<!--fastjson-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
2. common模块
common公共模块
<?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>
<parent>
<groupId>com.gdhd</groupId>
<artifactId>guigu-oa-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>common</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
3. common-util模块
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<scope>provided </scope>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</dependency>
</dependencies>
4. service-util模块
<dependency>
<!-- com.gdhd 是我搭建项目时候groupld的内容,需要更换你的 -->
<groupId>com.gdhd</groupId>
<artifactId>common-util</artifactId>
<version>0.0.1-SNAPSHOT</version>
</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>
</dependency>
<!--mysql-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>net.minidev</groupId>
<artifactId>json-smart</artifactId>
<version>2.4.11</version>
<scope>compile</scope>
</dependency>
</dependencies>
5. model模块
<dependencies>
<!--lombok用来简化实体类-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<scope>provided </scope>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<scope>provided </scope>
</dependency>
</dependencies>
注意:IDEA需要安装lombok插件,具体的操作可以参考配套文件中的课件搭建环境,也可以自己找资源,这边不过多介绍
6 service-oa模块
<dependencies>
<dependency>
<!-- com.gdhd 是我搭建项目时候groupld的内容,需要更换你的 -->
<groupId>com.gdhd</groupId>
<artifactId>model</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.gdhd</groupId>
<artifactId>service-util</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
三、数据库与实体类操作
3.1 生成数据库
配套文件中的资料文件夹中有相关数据库,直接利用文件生成即可,不过多说明
3.2 导入实体类
将配套文件夹中的资料文件的实体类进行复制到model模块下的src/main/java路径下
引入以后,可以重新刷新maven
3.3 配置文件
放在service-oa模块下的src/main/resources
- 创建application.yml文件
spring:
application:
name: service-oa
profiles:
# 指定开发环境
active: dev
- 创建application-dev.yml文件
server:
#端口号
port: 8800
mybatis-plus:
configuration:
# 日志信息配置
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
spring:
# 数据库相关信息
datasource:
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/guigu-oa?serverTimezone=GMT%2B8&characterEncoding=utf-8&useSSL=false
username: root
password: root
mvc:
pathmatch:
matching-strategy: ant_path_matcher
# 配置日期时间格式
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
注意:连接地址url
- MySQL5.7版本的url:jdbc:mysql://localhost:3306/mybatis_plus?characterEncoding=utf-8&useSSL=false
- MySQL8.0版本的url:jdbc:mysql://localhost:3306/mybatis_plus?
serverTimezone=GMT%2B8&characterEncoding=utf-8&useSSL=false - 否则运行测试用例报告如下错误:java.sql.SQLException: The server time zone value ‘Öйú±ê׼ʱ¼ä’ is unrecognized or
represents more
四 搭建前端开发
4.1 相关说明
- 前端软件使用:vsCode 软件进行开发
- 需要安装 node.js,安装版本为10.14.2版本太高会报错,资料文件中的工具包有对应的node.js安装包
- 前端压缩包在配套资料
4.2 安装与运行
#修改项目名称 vue-admin-template 改为 guigu-auth-ui
# 解压压缩包
# 进入目录
cd guigu-auth-ui
# 安装依赖
npm install
# 启动。执行后,浏览器自动弹出并访问http://localhost:9528/
npm run dev
4.4 前后端跨域
- 在前端工程的vue.config.js中进行跨域配置
- 注释掉mock接口配置
- 配置代理转发请求到目标接口
// before: require('./mock/mock-server.js')
proxy: {
'/dev-api': { // 匹配所有以 '/dev-api'开头的请求路径
target: 'http://localhost:8800',
changeOrigin: true, // 支持跨域
pathRewrite: { // 重写路径: 去掉路径中开头的'/dev-api'
'^/dev-api': ''
}
}
}
主要还是看尚硅谷的搭建,我的登录没有写,后续我将主要是分析