程序员的资源宝库

网站首页 > gitee 正文

第162天学习打卡(谷粒商城4 逆向生成所有微服务的CRUD)

sanyeah 2024-04-13 16:11:58 gitee 3 ℃ 0 评论

逆向生成所有微服务的CRUD代码

Product

把在Git上克隆下的RENREN-FAST-VUE拖入Visual Studio Code中之后,执行以下命令

npm install 
npm run dev

执行成功后会出现: I Your application is running here: http://localhost:8001,点击这个链接进行查看。

image-20210619163056893

登录这个页面使用的账号和密码都是admin,登录的页面的显示:

image-20210619163350473

在码云上搜索人人开源,选择下面这个:

renren-generator: 人人开源项目的代码生成器,可在线生成entity、xml、dao、service、vue、sql代码,减少70%以上的开发任务 (gitee.com)

image-20210619163707435

image-20210619163800526

在Git里面把下面克隆下来

$ git clone https://gitee.com/renrenio/renren-generator.git

image-20210619164005326

把克隆下来的renren-generator里面的.git文件删除,然后放入gulimall这个总文件下

image-20210619164301442

image-20210619164359661

image-20210619164635184

修改renren-generator的配置文件

image-20210619165314143

image-20210619170245617

启动这个generator项目之后,访问localhost:80

image-20210619172214274

image-20210619172230537

image-20210619172409819

生成代码的压缩包解压把里面的main文件夹复制到gulimall-product里面的main

image-20210619174118865

image-20210619174334793

创建一个maven模块

image-20210619185900432

创建的gulimall-common里面需要的文件我们从renren-fast里面拷贝

image-20210619195657207

image-20210619195912680

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>

image-20210619191717518

image-20210619193315424

修改了IDEA中的renren-generator的逆向工程 要重新生成代码

image-20210619193954984

image-20210619195358286

image-20210619201751258

在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("保存成功...");
    }

}

输出结果

image-20210619205152838

image-20210619205608786

在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);

    }

}

结果显示

image-20210619210009668

在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);

        });


    }

}

结果显示

image-20210619210943899

Coupon

修改配置文件:

image-20210619211442210

image-20210619211558957

image-20210619211852802

访问localhost:80 ,勾选表名之后生成代码

image-20210619212013192

image-20210619212441971

在gulimall-coupon里面导入依赖

pom.xml

    <dependency>            <groupId>com.doudou.gulimall1</groupId>            <artifactId>gulimall-common</artifactId>            <version>0.0.1-SNAPSHOT</version>        </dependency>

image-20210619212904957

在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.Drivermybatis-plus:  mapper-locations: classpath:/mapper/**/*.xml  global-config:    db-config:      id-type: autoserver:  port: 7000

测试运行:

image-20210619213547608

访问浏览器页面:localhost:8080/coupon/coupon/list

image-20210619213602314

member

修改配置文件

image-20210619213922435

image-20210619214055086

image-20210619214234998

生成代码:

image-20210619214322130

image-20210619214748278

在gulimall-member的pom.xml中导入相关依赖

<dependency>            <groupId>com.doudou.gulimall1</groupId>            <artifactId>gulimall-common</artifactId>            <version>0.0.1-SNAPSHOT</version>        </dependency>

image-20210619215040005

在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

启动测试

image-20210619220314426

注意点:要把application.properties里面的端口注释掉

在浏览器中进行访问:

localhost:8000/member/growthchangehistory/list

image-20210619220609461

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.Drivermybatis-plus:  mapper-locations: classpath:/mapper/**/*.xml  global-config:    db-config:      id-type: autoserver:  port: 9000

修改配置文件

image-20210619220916169

image-20210619221031366

image-20210619221126389

生成代码

image-20210619221228050

image-20210619221555443

在pom.xml中导入相关依赖

 <dependency>
            <groupId>com.doudou.gulimall1</groupId>
            <artifactId>gulimall-common</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>

在浏览器中访问

localhost:9000/order/order/list

image-20210619222220581

ware

修改配置文件

image-20210619222446309

image-20210619222603892

image-20210619222651034

image-20210619222808419

image-20210619223204336

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: 11000

导入相关依赖

pom.xml

 <dependency>
            <groupId>com.doudou.gulimall1</groupId>
            <artifactId>gulimall-common</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>

出错

image-20210619223629632

解决办法把出错的地方改为Byte

浏览器进行访问:

image-20210619223938797

B站学习网址:全网最强电商教程《谷粒商城》对标阿里P6/P7,40-60万年薪_哔哩哔哩_bilibili

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表