开启掘金成长之旅!这是我参与「掘金日新计划 · 2 月更文挑战」的第 1 天,点击查看活动详情
项目介绍
学成在线项目包括用户端、机构端、运营端,核心模块包括内容管理、媒资管理、课程搜索、订单支付、选课管理、认证授权等。它采用前后端分离架构,后端采用springboot、springcloud技术栈进行开发。划分的微服务包括:内容管理服务、媒资管理服务、搜索服务、订单支付服务、 学习中心服务、系统管理服务、认证授权服务、网关服务、注册中心服务、配置中心服务等。
环境搭建
数据库表的导入就用navicat去导就行了,没什么好说的。
项目结构如下:
我们首先要创建一个maven工程,可以取名为
xuecheng-plus。以内容管理这个微服务为例,通过idea中->file->project structure->new module依次创建xuecheng-plus-parent、xuecheng-plus-base、xuecheng-plus-content这三个springboot并列工程(boot版本选择2.3.7.RELEASE)。其中parent这个工程是父工程,主要用来做版本管理,要注意的是它的packing需要改成pom。
<packaging>pom</packaging>
然后创建base工程。base工程需要继承parent工程,所以pom中需要注意的点是:
<parent>
<groupId>com.xuecheng</groupId>
<artifactId>xuecheng-plus-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../xuecheng-plus-parent</relativePath>
</parent>
上述方式就会形成base继承parent工程,接下来需要创建模块(content)管理的工程结构。
模块管理的工程结构
在前后端分离项目中,前端与后端开发人员之间主要依据接口进行开发。前后端交互图如下:
整个流程主要分为:前端、接口层、业务层,所以后端工程结构应该是接口工程、业务工程、数据模型工程。我们的内容管理模块工程结构应该是这样的:
再结合父工程结构,整个工程结构如下;
前面我们已经创建了parent、base工程,接着我们依次创建
xuecheng-plus-content、xuecheng-plus-content-api、xuecheng-plus-content-service、xuecheng-plus-content-model工程。
content是内容管理模块中的父工程与base并列,一同继承parent工程。我们创建xuecheng-plus-content工程与base、parent工程在同一级目录。pom继承代码如下:
<parent>
<groupId>com.xuecheng</groupId>
<artifactId>xuecheng-plus-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../xuecheng-plus-parent</relativePath>
</parent>
<artifactId>xuecheng-plus-content</artifactId>
<packaging>pom</packaging>
pom中packing方式也设置成pom是因为content是service、model、api的父工程,对于三个子工程的管理后面再写。这三个工程与content工程层级关系如下;
接着,创建model、api、service等子工程。主要针对其pom进行介绍:首先是model的pom文件
<parent>
<groupId>com.xuecheng</groupId>
<artifactId>xuecheng-plus-content</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>xuecheng-plus-content-model</artifactId>
<dependencies>
<dependency>
<groupId>com.xuecheng</groupId>
<artifactId>xuecheng-plus-base</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
在parent标签处,我们书写继承关系,继承content。在dependency标签下我们写依赖关系,依赖于base工程。api和service也可以采用这样的做法来写两者的继承与依赖关系(先是api工程的pom):
<parent>
<groupId>com.xuecheng</groupId>
<artifactId>xuecheng-plus-content</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>xuecheng-plus-content-api</artifactId>
<dependencies>
<dependency>
<groupId>com.xuecheng</groupId>
<artifactId>xuecheng-plus-content-model</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.xuecheng</groupId>
<artifactId>xuecheng-plus-content-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
同样继承content工程,依赖model与service。service工程的依赖相对api工程只少了个对service的依赖,就不言述了。最后,工程结构如图;
generator是后面的东西,这里就先不说。