第162天学习打卡(谷粒商城4 逆向生成所有微服务的CRUD)
2021/6/19 23:27:24
本文主要是介绍第162天学习打卡(谷粒商城4 逆向生成所有微服务的CRUD),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
逆向生成所有微服务的CRUD代码
Product
把在Git上克隆下的RENREN-FAST-VUE拖入Visual Studio Code中之后,执行以下命令
npm install npm run dev
执行成功后会出现: I Your application is running here: http://localhost:8001,点击这个链接进行查看。
登录这个页面使用的账号和密码都是admin,登录的页面的显示:
在码云上搜索人人开源,选择下面这个:
renren-generator: 人人开源项目的代码生成器,可在线生成entity、xml、dao、service、vue、sql代码,减少70%以上的开发任务 (gitee.com)
在Git里面把下面克隆下来
$ git clone https://gitee.com/renrenio/renren-generator.git
把克隆下来的renren-generator里面的.git文件删除,然后放入gulimall这个总文件下
修改renren-generator的配置文件
启动这个generator项目之后,访问localhost:80
生成代码的压缩包解压把里面的main文件夹复制到gulimall-product里面的main
创建一个maven模块
创建的gulimall-common里面需要的文件我们从renren-fast里面拷贝
gulimall-common里面的pom.xml
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactId>gulimall1-ware</artifactId> <groupId>com.doudou.gulimall1</groupId> <version>0.0.1-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>gulimall-common</artifactId> <description>每个微服务公共的依赖, bean,工具类等</description> <properties> <maven.compiler.source>8</maven.compiler.source> <maven.compiler.target>8</maven.compiler.target> </properties> <dependencies> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.4.3.1</version> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.16.18</version> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore --> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpcore</artifactId> <version>4.4.14</version> </dependency> <dependency> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> <version>2.6</version> </dependency> <dependency> <groupId>io.renren</groupId> <artifactId>renren-fast</artifactId> <version>3.0.0</version> <scope>compile</scope> </dependency> <!-- 导入mysql驱动--> <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.23</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>3.0-alpha-1</version> <scope>provided</scope> </dependency> </dependencies> </project>
gulimall-product的pom.xml需要导入的依赖
<dependency> <groupId>com.doudou.gulimall1</groupId> <artifactId>gulimall-common</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency>
修改了IDEA中的renren-generator的逆向工程 要重新生成代码
在gulimall-product中的resources下创建application.yaml文件
application.yaml
spring: datasource: username: root password: 123456 url: jdbc:mysql://数据库连接地址:3306/gulimall_pms?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8 driver-class-name: com.mysql.cj.jdbc.Driver mybatis-plus: mapper-locations: classpath:/mapper/**/*.xml global-config: db-config: id-type: auto server: port: 10000
在gulimall.product的Test里面进行测试1:
package com.doudou.gulimall.product; import com.doudou.gulimall.product.entity.BrandEntity; import com.doudou.gulimall.product.service.BrandService; import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @SpringBootTest class GulimallProductApplicationTests { @Autowired BrandService brandService; @Test public void contextLoads() { BrandEntity brandEntity = new BrandEntity(); brandEntity.setName("华为"); brandService.save(brandEntity); System.out.println("保存成功..."); } }
输出结果:
在gulimall.product的Test里面进行测试2:
package com.doudou.gulimall.product; import com.doudou.gulimall.product.entity.BrandEntity; import com.doudou.gulimall.product.service.BrandService; import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @SpringBootTest class GulimallProductApplicationTests { @Autowired BrandService brandService; @Test public void contextLoads() { BrandEntity brandEntity = new BrandEntity(); brandEntity.setBrandId(1L); brandEntity.setDescript("华为"); // brandEntity.setName("华为"); // brandService.save(brandEntity); // System.out.println("保存成功..."); brandService.updateById(brandEntity); } }
结果显示
在gulimall.product的Test里面进行测试3:
package com.doudou.gulimall.product; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.doudou.gulimall.product.entity.BrandEntity; import com.doudou.gulimall.product.service.BrandService; import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; import java.util.List; @RunWith(SpringRunner.class) @SpringBootTest class GulimallProductApplicationTests { @Autowired BrandService brandService; @Test public void contextLoads() { // BrandEntity brandEntity = new BrandEntity(); // brandEntity.setBrandId(1L); // brandEntity.setDescript("华为"); //// brandEntity.setName("华为"); //// brandService.save(brandEntity); //// System.out.println("保存成功..."); // brandService.updateById(brandEntity); List<BrandEntity> list = brandService.list(new QueryWrapper<BrandEntity>().eq("brand_id", 1L)); list.forEach((item)->{ System.out.println(item); }); } }
结果显示
Coupon
修改配置文件:
访问localhost:80 ,勾选表名之后生成代码
在gulimall-coupon里面导入依赖
pom.xml
<dependency> <groupId>com.doudou.gulimall1</groupId> <artifactId>gulimall-common</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency>
在resources里面新建一个application.yml文件进行配置
spring: datasource: username: root password: 123456 url: jdbc:mysql://数据库连接地址:3306/gulimall_sms?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8 driver-class-name: com.mysql.cj.jdbc.Driver mybatis-plus: mapper-locations: classpath:/mapper/**/*.xml global-config: db-config: id-type: auto server: port: 7000
测试运行:
访问浏览器页面:localhost:8080/coupon/coupon/list
member
修改配置文件
生成代码:
在gulimall-member的pom.xml中导入相关依赖
<dependency> <groupId>com.doudou.gulimall1</groupId> <artifactId>gulimall-common</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency>
在gulimall-member下的resources下新建application.yml文件
application.yml
spring: datasource: username: root password: 123456 url: jdbc:mysql://数据库连接地址:3306/gulimall_ums?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8 driver-class-name: com.mysql.cj.jdbc.Driver mybatis-plus: mapper-locations: classpath:/mapper/**/*.xml global-config: db-config: id-type: auto server: port: 8000
启动测试
注意点:要把application.properties里面的端口注释掉
在浏览器中进行访问:
localhost:8000/member/growthchangehistory/list
order
application.yml
spring: datasource: username: root password: 123456 url: jdbc:mysql://数据库连接地址:3306/gulimall_oms?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8 driver-class-name: com.mysql.cj.jdbc.Driver mybatis-plus: mapper-locations: classpath:/mapper/**/*.xml global-config: db-config: id-type: auto server: port: 9000
修改配置文件
生成代码
在pom.xml中导入相关依赖
<dependency> <groupId>com.doudou.gulimall1</groupId> <artifactId>gulimall-common</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency>
在浏览器中访问
localhost:9000/order/order/list
ware
修改配置文件
application.yml
spring: datasource: username: root password: 123456 url: jdbc:mysql://数据库连接地址:3306/gulimall_wms?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8 driver-class-name: com.mysql.cj.jdbc.Driver mybatis-plus: mapper-locations: classpath:/mapper/**/*.xml global-config: db-config: id-type: auto server: port: 10001
导入相关依赖
pom.xml
<dependency> <groupId>com.doudou.gulimall1</groupId> <artifactId>gulimall-common</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency>
出错
解决办法把出错的地方改为Byte
B站学习网址:全网最强电商教程《谷粒商城》对标阿里P6/P7,40-60万年薪哔哩哔哩bilibili
这篇关于第162天学习打卡(谷粒商城4 逆向生成所有微服务的CRUD)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-23新能源车企如何通过CRM工具优化客户关系管理,增强客户忠诚度与品牌影响力
- 2024-12-23原创tauri2.1+vite6.0+rust+arco客户端os平台系统|tauri2+rust桌面os管理
- 2024-12-23DevExpress 怎么实现右键菜单(Context Menu)显示中文?-icode9专业技术文章分享
- 2024-12-22怎么通过控制台去看我的页面渲染的内容在哪个文件中呢-icode9专业技术文章分享
- 2024-12-22el-tabs 组件只被引用了一次,但有时会渲染两次是什么原因?-icode9专业技术文章分享
- 2024-12-22wordpress有哪些好的安全插件?-icode9专业技术文章分享
- 2024-12-22wordpress如何查看系统有哪些cron任务?-icode9专业技术文章分享
- 2024-12-21Svg Sprite Icon教程:轻松入门与应用指南
- 2024-12-20Excel数据导出实战:新手必学的简单教程
- 2024-12-20RBAC的权限实战:新手入门教程