四、人人开源
文章目錄
- 一、整合人人開源
- 1.整合人人開源
- 二、公共模塊
- 1.公共模塊
- 2.公共模塊的pom.xml增加內(nèi)容
- 3.整合mybatis-plus
- 逆向生成所有微服務(wù)基本CRUD代碼
一、整合人人開源
1.整合人人開源
打開git 的 git bash here ,使用命令 git clone https://gitee.com/renrenio/renren-fast.git
在找到 renren-fast-vue ,在克隆 / 下 載那里 復(fù)制https, 使用命令git clone https://gitee.com/renrenio/renren-fast-vue.git
快捷鍵打開idea項目文件夾
配置npm淘寶鏡像:npm config set registry http://registry.npm.taobao.org/
在前端項目讓maven下載依賴的組件 npm install ,如果失敗,去git下載人人開源的vue的zip文件 ,再npm install 成功后,npm run dev
使用代碼生成器:(1)改application.yml文件中的數(shù)據(jù)庫信息:
(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方法
在頁面的renren-fast全部勾選
會將代碼生成一個壓縮包,打開解壓的文件,將main文件粘貼到對應(yīng)的微服務(wù)模塊里,會多出來一些內(nèi)容,不要刪掉之前存在的main文件。把resource下的src文件夾刪掉,里面是vue文件。
建一個公共模塊 ,將每一個微服務(wù)公共的內(nèi)容放在這個模塊,shift+F6 修改模塊名 rename module
在product項目的pom.xml加入,增加application.yml文件,改端口號
二、公共模塊
1.公共模塊
1)建包com/atguigu/common/utils、 com/atguigu/common/xss
將人人項目下的工具類PageUtils、Query、Constant、R、RRException 復(fù)制到untis包。將HTMLFilter、SQLFilter復(fù)制到xss包
2.公共模塊的pom.xml增加內(nèi)容
<description>每一個微服務(wù)公共的依賴,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><!-- 導(dǎo)入mysql驅(qū)動 --><!-- 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><!-- 服務(wù)注冊/發(fā)現(xiàn) --><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.導(dǎo)入依賴 (公共模塊)
<!-- mybatis-plus --><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.2.0</version></dependency>2.配置
1)配置數(shù)據(jù)源
jar包下載
(1)導(dǎo)入數(shù)據(jù)庫驅(qū)動 (公共模塊)
例如:(公共模塊)
(2)在application.yml文件配置數(shù)據(jù)源信息、指定端口號 (業(yè)務(wù)模塊)
例如:在product模塊,創(chuàng)建application.yml文件,內(nèi)容:
2)配置mybatis-plus
1)使用@MapperScan
例如:在啟動類加注解:@MapperScan(“com.atguigu.gulimall.product.dao”)
2)告訴mybatis-plus sql映射文件
例如: 在product模塊的application.yml加內(nèi)容:
逆向生成所有微服務(wù)基本CRUD代碼
在其他的項目的pom.xml引入公共模塊,增加application.yml文件,改端口號
1)改application.yml文件中的數(shù)據(jù)庫信息:
(2)generator.properties 修改:
mainPath=com.atguigu #主目錄 package=com.atguigu.gulimall #包名 moduleName=coupon #模塊名 tablePrefix=sms_ #表前綴(類名不會包含表前綴)(3)將resources下template下的controller中的所有requiresPermissions注解注釋掉
##import org.apache.shiro.authz.annotation.RequiresPermissions;## @RequiresPermissions("${moduleName}:${pathName}:info")(4)啟動 人人開源renren-generator 啟動類 ,點IDEA啟動類的80端口,進入頁面,點頁面的renren-fast,頁面條數(shù)調(diào)大才能選中所有表,點“生成代碼”按鈕。
(5)解壓生成的文件,復(fù)制main文件夾,粘貼到對應(yīng)微服務(wù)項目的main文件夾,會多一些內(nèi)容。
(6)刪掉resource文件夾下面的src文件夾
(7)創(chuàng)建application.yml文件,改數(shù)據(jù)庫名、端口號
總結(jié)
- 上一篇: 我的Blog不值钱
- 下一篇: breakcontinue