一、整合人人开源
1.整合人人开源
- gitee搜索人人开源,找到renren-fast,在克隆 / 下载那里 复制https,
打开git 的 git bash here ,使用命令git clone https://gitee.com/renrenio/renren-fast.git
在找到 renren-fast-vue ,在克隆 / 下 载那里 复制https, 使用命令git clone https://gitee.com/renrenio/renren-fast-vue.git
- 删掉下载的这两个文件夹里面的git
快捷键打开idea项目文件夹
- 将renren-fast 文件夹托到项目的根目录,并在总项目的pom.xml里加入
<module>renren-fast</module>
- 打开sqlyog,创建数据库gulimall_admin,将renren-fast文件下的db的sql文件复制到sqlyog,全选以后执行导入
- 修改renren-fast的application-dev.yml文件:修改数据库连接地址以及账号密码 ,运行程序
url: jdbc:mysql://192.168.56.10:3306/gulimall_admin?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
username: root
password: root
- 用webStorm打开renren-fast-vue,先安装node.js ,官网下载http://nodejs.cn/api/ ,进行安装 ,使用命令 node -v 检查,
配置npm淘宝镜像:npm config set registry http://registry.npm.taobao.org/
在前端项目让maven下载依赖的组件 npm install ,如果失败,去git下载人人开源的vue的zip文件 ,再npm install 成功后,npm run dev
默认登录账号密码:admin admin - 代码生成器,去git下载人人开源renren-generator, 打开git 的 git bash here ,打开git的使用命令:https://gitee.com/renrenio/renren-generator.git
- 将文件夹放到根目录,把.git文件夹删掉,在根项目的pom.xml加入renren-generator-master 或 renren-generator
使用代码生成器:(1)改application.yml文件中的数据库信息:
url: jdbc:mysql://192.168.56.10:3306/gulimall_pms?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
username: root
password: root
(2)generator.properties 修改:
mainPath=com.atguigu #主目录
package=com.atguigu.gulimall #包名
moduleName=product #模块名
author=gys #作者
email= #Email
tablePrefix=pms_ #表前缀(类名不会包含表前缀)
(3)将resources下template下的controller中的所有requiresPermissions注解注释掉
##import org.apache.shiro.authz.annotation.RequiresPermissions;
## @RequiresPermissions("${moduleName}:${pathName}:info")
-
启动代码生成器的main方法,访问:http://localhost/#generator.html
-
在页面的renren-fast全部勾选
-
会将代码生成一个压缩包,打开解压的文件,将main文件粘贴到对应的微服务模块里,会多出来一些内容,不要删掉之前存在的main文件。把resource下的src文件夹删掉,里面是vue文件。
-
建一个公共模块 ,将每一个微服务公共的内容放在这个模块,shift+F6 修改模块名 rename module
在pom.xml中加入<description>每一个微服务公共的依赖,bean,工具类等</description>
-
在product项目的pom.xml加入,增加application.yml文件,改端口号
<dependency>
<groupId>gulimall</groupId>
<artifactId>gulimall-common</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
二、公共模块
1.公共模块
1)建包com/atguigu/common/utils、 com/atguigu/common/xss
将人人项目下的工具类PageUtils、Query、Constant、R、RRException 复制到untis包。将HTMLFilter、SQLFilter复制到xss包
2.公共模块的pom.xml增加内容
<description>每一个微服务公共的依赖,bean,工具类等</description>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>7</source>
<target>7</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- mybatis-plus -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.8</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.12</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<!-- 导入mysql驱动 -->
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.17</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<!-- 服务注册/发现 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!-- 配置中心来做配置管理 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>2.1.0.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
3.整合mybatis-plus
1.导入依赖 (公共模块)
<!-- mybatis-plus -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.2.0</version>
</dependency>
2.配置
1)配置数据源
jar包下载
(1)导入数据库驱动 (公共模块)
例如:(公共模块)
<!-- 导入mysql驱动 -->
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.17</version>
</dependency>
(2)在application.yml文件配置数据源信息、指定端口号 (业务模块)
例如:在product模块,创建application.yml文件,内容:
spring:
datasource:
username: root
password: root
url: jdbc:mysql://192.168.56.10:3306/gulimall_pms
driver-class-name: com.mysql.jdbc.Driver
server:
port: 10000
2)配置mybatis-plus
1)使用@MapperScan
例如:在启动类加注解:@MapperScan(“com.atguigu.gulimall.product.dao”)
2)告诉mybatis-plus sql映射文件
例如: 在product模块的application.yml加内容:
mybatis-plus:
mapper-locations: classpath:/mapper/**/*.xml
global-config:
db-config:
id-type: auto
logic-delete-value: 1
logic-not-delete-value: 0
4、逆向生成所有微服务基本CRUD代码
在其他的项目的pom.xml引入公共模块,增加application.yml文件,改端口号
- pom.xml引入公共模块
<dependency>
<groupId>gulimall</groupId>
<artifactId>gulimall-common</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
- 人人开源renren-generator 项目
1)改application.yml文件中的数据库信息:
优惠服务coupon:
url: jdbc:mysql://192.168.56.10:3306/gulimall_sms?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
username: root
password: root
会员服务member:
url: jdbc:mysql://192.168.56.10:3306/gulimall_ums?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
username: root
password: root
订单服务order:
url: jdbc:mysql://192.168.56.10:3306/gulimall_oms?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
username: root
password: root
库存服务ware:
url: jdbc:mysql://192.168.56.10:3306/gulimall_wms?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
username: root
password: root
(2)generator.properties 修改:
优惠服务coupon:
mainPath=com.atguigu #主目录
package=com.atguigu.gulimall #包名
moduleName=coupon #模块名
tablePrefix=sms_ #表前缀(类名不会包含表前缀)
会员服务member:
mainPath=com.atguigu #主目录
package=com.atguigu.gulimall #包名
moduleName=member #模块名
tablePrefix=ums_ #表前缀(类名不会包含表前缀)
订单服务order:
mainPath=com.atguigu #主目录
package=com.atguigu.gulimall #包名
moduleName=order #模块名
tablePrefix=oms_ #表前缀(类名不会包含表前缀)
库存服务ware:
mainPath=com.atguigu #主目录
package=com.atguigu.gulimall #包名
moduleName=ware #模块名
tablePrefix=wms_ #表前缀(类名不会包含表前缀)
(3)将resources下template下的controller中的所有requiresPermissions注解注释掉
##import org.apache.shiro.authz.annotation.RequiresPermissions;
## @RequiresPermissions("${moduleName}:${pathName}:info")
(4)启动 人人开源renren-generator 启动类 ,点IDEA启动类的80端口,进入http://localhost/#generator.html,点页面的renren-fast,页面条数调大才能选中所有表,点“生成代码”按钮。
(5)解压生成的文件,复制main文件夹,粘贴到对应微服务项目的main文件夹,会多一些内容。
(6)删掉resource文件夹下面的src文件夹
(7)创建application.yml文件,改数据库名、端口号
优惠服务coupon:
spring:
datasource:
username: root
password: root
url: jdbc:mysql://192.168.56.10:3306/gulimall_sms
driver-class-name: com.mysql.jdbc.Driver
mybatis-plus:
mapper-locations: classpath:/mapper/**/*.xml
global-config:
db-config:
id-type: auto
logic-delete-value: 1
logic-not-delete-value: 0
server:
port: 7000
会员服务member:
spring:
datasource:
username: root
password: root
url: jdbc:mysql://192.168.56.10:3306/gulimall_ums
driver-class-name: com.mysql.jdbc.Driver
mybatis-plus:
mapper-locations: classpath:/mapper/**/*.xml
global-config:
db-config:
id-type: auto
logic-delete-value: 1
logic-not-delete-value: 0
server:
port: 8000
订单服务order:
spring:
datasource:
username: root
password: root
url: jdbc:mysql://192.168.56.10:3306/gulimall_oms
driver-class-name: com.mysql.jdbc.Driver
mybatis-plus:
mapper-locations: classpath:/mapper/**/*.xml
global-config:
db-config:
id-type: auto
logic-delete-value: 1
logic-not-delete-value: 0
server:
port: 9000
库存服务ware:
spring:
datasource:
username: root
password: root
url: jdbc:mysql://192.168.56.10:3306/gulimall_wms
driver-class-name: com.mysql.jdbc.Driver
mybatis-plus:
mapper-locations: classpath:/mapper/**/*.xml
global-config:
db-config:
id-type: auto
logic-delete-value: 1
logic-not-delete-value: 0
server:
port: 11000
- 启动 测试
优惠服务coupon:
http://localhost:7000/coupon/coupon/list
会员服务member:
http://localhost:8000/member/growthchangehistory/list
订单服务order:
http://localhost:9000/order/order/list
库存服务ware:
http://localhost:11000/ware/purchase/list