逆向工程搭建
7.1 product
git clone https://gitee.com/renrenio/renren-generator.git
下載到桌面后,同樣把里面的.git文件刪除,然后移動到我們IDEA項目目錄中,同樣配置好pom.xml(root)
在common項目中增加module
<modules>
<module>gulimall-coupon</module>
<module>gulimall-member</module>
<module>gulimall-order</module>
<module>gulimall-product</module>
<module>gulimall-ware</module>
<module>renren-fast</module>
<module>renren-generator</module>
</modules>
修改renren-generator的application.yml
url: jdbc:mysql://192.168.1.103:3306/gulimall-pms?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
username: root
password: root
修改generator.properties
mainPath=com.yxj # 主目錄
package=com.yxj.gulimall # 包名
moduleName=product # 模塊名
author=yxj # 作者
email=xxx@qq.com # email
tablePrefix=pms_ # 我們的pms數據庫中的表的前綴都有pms,
如果寫了表前綴,每一張表對于的javaBean就不會添加前綴了
運行RenrenApplication。如果啟動不成功,修改application中是port為80。訪問http://localhost:80
然后點擊全部,點擊生成代碼。下載了壓縮包
解壓壓縮包,把main放到gulimall-product的同級目錄下。
在common項目的pom.xml(我們把每個微服務里公共的類和依賴放到common里。)中添加
<!-- mybatisPLUS-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.3.2</version>
</dependency>
<!--簡化實體類,用@Data代替getset方法-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.8</version>
</dependency>
<!-- httpcomponent包https://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.13</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
然后在product項目中的pom.xml中加入下面內容
<dependency>
<groupId>com.atguigu.gulimall</groupId>
<artifactId>gulimall-common</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
復制
renren-fast----utils包下的Query和PageUtils、R、Constant復制到common項目的java/com.yxj.common.utils下
把@RequiresPermissions這些注解掉,因為是shiro的
復制renren-fast中的xss包粘貼到common的java/com.yxj.common目錄下。
還復制了exception文件夾,對應的位置關系自己觀察一下就行
注釋掉product項目下類中的//import org.apache.shiro.authz.annotation.RequiresPermissions;,他是shiro的東西
注釋renren-generator\src\main\resources\template/Controller中所有的
# @RequiresPermissions。
# import org.apache.shiro.authz.annotation.RequiresPermissions;
總之什么報錯就去renren-fast里面找。
測試
測試與整合商品服務里的mybatisplus
在common的pom.xml中導入
<!-- 數據庫驅動 https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.17</version>
</dependency>
<!--tomcat里一般都帶-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope> # Tomcat有帶,所以provided
</dependency>
刪掉common里xss/xssfiler和XssHttpServletRequestWrapper
在product項目的resources目錄下新建application.yml
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://192.168.1.103:3306/gulimall_pms?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
username: root
password: root
# MapperScan
# sql映射文件位置
mybatis-plus:
mapper-locations: classpath:/mapper/**/*.xml
global-config:
db-config:
id-type: auto
然后在主啟動類上加上注解@MapperScan()
@MapperScan("com.yxj.gulimall.product.dao")
@SpringBootApplication
public class gulimallProductApplication {
public static void main(String[] args) {
SpringApplication.run(gulimallProductApplication.class, args);
}
}
然后去測試,先通過下面方法給數據庫添加內容
@SpringBootTest
class gulimallProductApplicationTests {
@Autowired
BrandService brandService;
@Test
void contextLoads() {
BrandEntity brandEntity = new BrandEntity();
brandEntity.setDescript("hello");
brandEntity.setName("華為");
brandService.save(brandEntity);
System.out.println("保存成功");
}
}
3.12.2 coupon
重新打開generator逆向工程,修改generator.properties
# 主目錄
mainPath=com.yxj
package=com.yxj.gulimall
moduleName=coupon
autho=yxj
email=xxx@qq.com
tablePrefix=sms_
修改yml數據庫信息
spring:
datasource:
username: root
password: root
url: jdbc:mysql://192.168.1.103:3306/gulimall_sms?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
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
啟動生成RenrenApplication.java,運行后去瀏覽器80端口查看,同樣讓他一
頁全顯示后選擇全部后生成。生成后解壓復制到coupon項目對應目錄下。
讓coupon也依賴于common,修改pom.xml
<dependency>
<groupId>com.atguigu.gulimall</groupId>
<artifactId>gulimall-common</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
resources下src包先刪除
添加application.yml
spring:
datasource:
username: root
password: root
url: jdbc:mysql://192.168.1.103:3306/gulimall_sms?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
driver-class-name: com.mysql.cj.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
運行gulimallCouponApplication.java
http://localhost:8080/coupon/coupon/list
{"msg":"success","code":0,"page":{"totalCount":0,"pageSize":10,"totalPage":0,"currPage":1,"list":[]}}
3.12.3 member
重新使用代碼生成器生成ums
模仿上面修改下面兩個配置
代碼生成器里:
url: jdbc:mysql://192.168.1.103:3306/gulimall_sms?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
mainPath=com.yxj
package=com.yxj.gulimall
moduleName=member
author=yxj
email=xxx@qq.com
tablePrefix=ums_
重啟RenrenApplication.java,然后同樣去瀏覽器獲取壓縮包解壓到對應member項目目錄
member也導入依賴
<dependency>
<groupId>com.atguigu.gulimall</groupId>
<artifactId>gulimall-common</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
同樣新建application.yml
spring:
datasource:
username: root
password: root
url: jdbc:mysql://192.168.1.103:3306/gulimall-ums?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
driver-class-name: com.mysql.cj.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端口是9000,product是10000,ware是11000。
以后比如order系統要復制多份,他的端口計算9001、9002。。。
重啟web后,http://localhost:8000/member/growthchangehistory/list
測試成功:{"msg":"success","code":0,"page":{"totalCount":0,"pageSize":10,"totalPage":0,"currPage":1,"list":[]}}
3.12.4 order
修改代碼生成器
jdbc:mysql://192.168.1.103:3306/gulimall_oms?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
#代碼生成器,配置信息
mainPath=com.yxj
package=com.yxj.gulimall
moduleName=order
author=yxj
email=xxx@qq.com
tablePrefix=oms_
運行RenrenApplication.java重新生成后去下載解壓放置。
application.yml
spring:
datasource:
username: root
password: root
url: jdbc:mysql://192.168.1.103:3306/gulimall_oms?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
driver-class-name: com.mysql.cj.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
在pom.xml添加
<dependency>
<groupId>com.atguigu.gulimall</groupId>
<artifactId>gulimall-common</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
啟動gulimallOrderApplication.java
http://localhost:9000/order/order/list
{"msg":"success","code":0,"page":{"totalCount":0,"pageSize":10,"totalPage":0,"currPage":1,"list":[]}}
3.12.5 ware
修改代碼生成器
jdbc:mysql://192.168.1.103:3306/gulimall_wms?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
#代碼生成器,配置信息
mainPath=com.yxj
package=com.yxj.gulimall
moduleName=ware
author=yxj
email=xxx@qq.com
tablePrefix=wms_
運行RenrenApplication.java重新生成后去下載解壓放置。
application.yml
spring:
datasource:
username: root
password: root
url: jdbc:mysql://192.168.1.103:3306/gulimall_wms?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
driver-class-name: com.mysql.cj.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
在pom.xml添加
<dependency>
<groupId>com.atguigu.gulimall</groupId>
<artifactId>gulimall-common</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
啟動gulimallWareApplication.java
http://localhost:11000/ware/wareinfo/list
{"msg":"success","code":0,"page":{"totalCount":0,"pageSize":10,"totalPage":0,"currPage":1,"list":[]}}