GithubHelp home page GithubHelp logo

wangsun300 / mybatis-plus-code-generator Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fengwenyi/mybatis-plus-code-generator

0.0 1.0 0.0 42 KB

MyBatis-Plus代码生成器

Home Page: https://mp.baomidou.com/guide/generator.html

License: MIT License

Java 100.00%

mybatis-plus-code-generator's Introduction

MyBatis-Plus 代码生成器

Current Version

3.4.1

概述

代码生成器,又被叫做逆向工程,MyBatis官方为了推广,自己也写了一个,我之前也使用这个,功能也是非常强大,强大以为支持自定义配置,那么问题来了,我该怎么配置才合理呢,所以,有人把所有的配置项都弄成中文的,还有人开发了生成插件,这些在我以往的博文中都看看到。MyBatis-Plus的代码生成器到底怎么样,这我就不评判了,我就这样说,用用看吧。

功能列表:

  • 自动生成model类

  • 自动生成dao接口

  • 自动生成xml文件

  • 自动生成service接口

  • 自动生成service实现类

  • model支持Builder模式

  • 支持swagger2

  • 支持生成数据库字段常量

  • 支持生成Kotlin代码

  • ……more……

目录结构

.
├── README.md
├── pom.xml
└── src
    ├── main
    │   └── java
    │       └── com
    │           └── fengwenyi
    │               └── code_generator
    │                   ├── Config.java                      // 自定义配置
    │                   ├── MySQL8CodeGenerator.java         // MySQL代码生成器
    │                   ├── OracleCodeGenerator.java         // Oracle代码生成器
    │                   └── util
    │                       └── CommonUtils.java
    └── test
        └── java
            └── com
                └── fengwenyi
                    └── code_generator
                        └── CodeGeneratorTests                // 代码生成器测试

支持的数据库

  • MySQL

  • Oracle

  • SQL Server

快速开始

你只需要三步,就能生成代码

第一步:Git克隆

git clone [email protected]:fengwenyi/mybatis-plus-code-generator.git

第二步:IDE导入

第三步:简单且必应的配置即可运行

MySQL:MySQL8CodeGenerator

Oracle:OracleCodeGenerator

简单且必要的配置

参数名 说明 示例值
dbUrl 数据库连接URL jdbc:mysql://localhost:3306/dbName
username 数据库用户名 dbUsername
password 数据库密码 dbPassword
driver 数据库连接驱动 com.mysql.cj.jdbc.Driver
tablePrefixes 表前缀,生成的实体类,不含前缀 t
tableNames 表名,为空,生成所有的表 t_user, t_goods, t_order
fieldPrefixes 字段前缀 -
packageName 基础包名 com.example.module.db

更多配置项

com.fengwenyi.code_generator.Config

参数名 说明 默认值
PACKAGE_NAME_CONTROLLER 数据库控制层包名 controller
PACKAGE_NAME_SERVICE 数据库服务接口包名 repository
PACKAGE_NAME_SERVICE_IMPL 数据库服务接口实现类包名 repository.impl
PACKAGE_NAME_MODEL 数据库实体类包名 entity
PACKAGE_NAME_DAO 数据库操作接口包名 dao
DIR_NAME_XML MyBatis XML文件夹名称 mapper
FILE_NAME_MODEL 数据库实体类文件名后缀 %sEntity
FILE_NAME_DAO 数据库操作接口文件名后缀 I%sDao
FILE_NAME_XML MyBatis XML文件名后缀 %sMapper
FILE_NAME_SERVICE 数据库服务接口文件名后缀 MP%sRepository
FILE_NAME_SERVICE_IMPL 数据库服务接口实现类文件名后缀 %sRepositoryImpl
FILE_NAME_CONTROLLER 数据库控制层文件名后缀 %sController
FIELD_LOGIC_DELETE_NAME 逻辑删除字段名称 delete_status
FIELD_VERSION_NAME 乐观锁字段名称 version
AUTHOR 类注释作者 Erwin Feng
PROJECT_PATH 工程路径 System.getProperty("user.dir")
OUTPUT_DIR 生成的文件路径 PROJECT_PATH + "/temp/code-generator"
TEMPLATE_ENGINE 模板引擎。velocity / freemarker / beetl velocity
SWAGGER_SUPPORT 生成的实体类是否支持Swagger false

注意事项

1、关于指定生成的表名

// 表名,为空,生成所有的表
String [] tableNames = {};

// 表名,具体表名
String [] tableNames = {"table"};

// 表名,多张表
String [] tableNames = {"table1", "table1"};

// 注意:生成多张表时,不能写成
String [] tableNames = {""};

2、包名

// 基础包名
// 这是基础包名,会在后面加dao/model/service等包名
String packageName = "com.example.module.db";

3、数据库操作服务接口默认以 MP 为前缀,如:MPUserService

4、报错 Error java: 错误;不支持发行版5

解决办法:

Java Compilermodule 对应的 java 版本改成 8+

mybatis-plus-code-generator's People

Contributors

fengwenyi avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.