通過逆向工程自動生成微服務代碼,提升70%的研發效率

本文講介紹如何藉助renren-generator,逆向自動生成全套的業務基礎代碼
在這裏插入圖片描述

一、引入renren-generator到需要逆向生成的微服務項目裏

git clone [email protected]:renrenio/renren-generator.git

1.1 修改application.yml的數據源

url: jdbc:mysql://192.168.20.3:3306/mall_pms?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai

1.2 調整generator.properties的生成路徑,如下圖
在這裏插入圖片描述
1.3 運行RenrenApplication,執行自動生成

二、不寫業務代碼,直接進行操作、驗證數據表

2.1 添加application.yml微服務配置

spring:
  datasource:
    username: root
    password: root
    url: jdbc:mysql://192.168.20.3:3306/gulimall_pms
    driver-class-name: com.mysql.jdbc.Driver
mybatis-plus:
  mapper-locations: classpath:/mapper/**/*.xml
  global-config:
    db-config:
      id-type: auto

2.2 單測

import com.yfy.gulimall.product.entity.BrandEntity;
import com.yfy.gulimall.product.service.BrandService;
import org.junit.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
public class GulimallProductApplicationTests {
    @Autowired
    BrandService brandService;

    @Test
    public void contextLoads() {
        BrandEntity brandEntity = new BrandEntity();
        brandEntity.setDescript("華爲");
        brandEntity.setName("華爲");
        brandService.save(brandEntity);
        System.out.println("保存成功....");
    }

}

2.3 數據庫測試結果
在這裏插入圖片描述

三、推薦配套使用的前後端分支

[email protected]:renrenio/renren-fast.git

[email protected]:renrenio/renren-fast-vue.git

[email protected]:renrenio/renren-generator.git

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章