逆向工程搭建
7.1 product
git clone https://gitee.com/renrenio/renren-generator.git
下载到桌面后,同样把里面的.git文件删除,然后移动到我们idea项目目录中,同样配置好pom.xml(root)
在common项目中增加module
gulimall-coupon
gulimall-member
gulimall-order
gulimall-product
gulimall-ware
renren-fast
renren-generator
修改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里。)中添加
com.baomidou
mybatis-plus-boot-starter 3.3.2
org.projectlombok
1.18.8
org.apache.httpcomponents
4.4.13
commons-lang
2.6
然后在product项目中的pom.xml中加入下面内容
com.atguigu.gulimall
0.0.1-snapshot
复制
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中导入
mysql
8.0.17
javax.servlet
2.5
provided # tomcat有带,所以provided
删掉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
com.atguigu.gulimall
0.0.1-snapshot
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也导入依赖
com.atguigu.gulimall
0.0.1-snapshot
同样新建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添加
com.atguigu.gulimall
0.0.1-snapshot
启动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添加
com.atguigu.gulimall
0.0.1-snapshot
启动gulimallwareapplication.java
http://localhost:11000/ware/wareinfo/list
{"msg":"success","code":0,"page":{"totalcount":0,"pagesize":10,"totalpage":0,"currpage":1,"list":[]}}