# code-generator-maven-plugin **Repository Path**: wkk-opensource/code-generator-maven-plugin ## Basic Information - **Project Name**: code-generator-maven-plugin - **Description**: 基于数据库表生成Controller, Service, entity, Dao CRUD代码的maven插件。支持 Mybatis, Mybatis-Plus, JPA。还支持生成 Dockerfile 文件以及相关 Docker 脚本:DockerImageBuild.bat, DockerImageBuildRun.bat, DockerImageDelete.bat - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: https://mengweijin.gitee.io/ - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 6 - **Created**: 2021-06-19 - **Last Updated**: 2022-05-24 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # code-generator-maven-plugin Language: [中文](README.zh.md)

gitee star github star

## Description code-generator-maven-plugin is based on baomidou's mybatis-plus-generator,a Maven plugin that generates code in a Maven project。Key features: - code-generator:**MyBatis**:Generate Controller.java, Service.java, Mapper.java, mapper.xml, Entity.java under MyBatis based on database tables; - code-generator:**MyBatis-Plus**:Generate Controller.java, Service.java, Mapper.java, mapper.xml, Entity.java under MyBatis-Plus based on database tables; - code-generator:**JPA**:Generate Controller.java, Service.java, Repository.java, Entity.java under JPA based on database tables; - code-generator:**Dockerfile**:Generate the Dockerfile file for the current project, along with the associated scripts: DockerImageBuild.bat, DockerImageBuildRun.bat, DockerImageDelete.bat - code-generator:**Docker-Build**:Build Docker Image based on the locally installed Docker - code-generator:**Docker-Deploy**:Build Docker image and deploy Docker container based on locally installed Docker - code-generator:**Docker-Delete**:Delete deployed Docker containers and Docker images based on the locally installed Docker - Theory can be extended to any background and front database table related technology: such as: vue.js. - The theory supports all databases that support JDBC connection: for example: DB2, DM, H2, Mariadb, MySQL, Oracle, Postgre, Sqlite, SQLServer, etc. ## how to use? Locate the code-generator-maven-plugin in the Intellij IDEA Maven module shown below and double-click the corresponding plug-in command. ![image](docs/image/code-generator-maven-plugin.png) **Notes** * The default Java code generation is under the target/code-generator/ directory of the current project. * The default package path is com.github.mengweijin. * The default Dockerfile and other files are generated in the target directory of the current project. ## Generating Java Code ### 1. General Use In the standard SpringBoot project, take Intellij IDEA, a development tool, as an example: the code-generator-maven-plugin was introduced into Maven ~~~~xml com.github.mengweijin code-generator-maven-plugin Latest Version sys_user, sys_role com.github.mengweijin.quickboot.mybatis.BaseEntity ~~~~ ### 2. Full Configuration to Use ~~~~xml com.github.mengweijin code-generator-maven-plugin Latest Version com.github.mengweijin mengweijin root root jdbc:mysql://192.168.83.128:3306/mwj_cms sys_user, rlt_user_role sys_, rlt_ com.github.mengweijin.BaseEntity true ~~~~ ## Parameter configuration instructions |Parameter Name|Mandatory|Sample|Description| |---:|:---|:---|:---| |outputPackage|No|com.github.mengweijin|The package path to code generation. The default: com.github.mengweijin| |author|No|mengweijin|Class annotation with the @Author value above. Default: take the user name of the current computer| |dbInfo.username|No|root|The database connection information. If it is a standard SpringBoot project, can be omitted, automatically read application.yml/yaml/properties file.| |dbInfo.password|No|root|Same as above| |dbInfo.url|No|jdbc:mysql://192.168.83.128:3306/test|Same as above| |tables|No|sys_user, rlt_user_role|Same as above| |tablePrefix|No|sys_, rlt_|The prefix of the database table name corresponding to the code to be generated. Once configured, the generated Entity class will no longer have a table prefix. For example, User, UserRole. If not configured, the generated Entity class is prefixed with a table. For example, SysUser, RltUserRole. Multiple table name prefixes are separated by commas.| |superEntityClass|No|com.github.mengweijin.quickboot.mybatis.BaseEntity|The generated Entity class inherits the parent class.| |lombokModel|No|true|Whether the generated Entity is Lombok enabled. Unconfigured or true: Enable Lombok mode; Set to false: If Lombok is not enabled, the generated entity contains getter/setter/toString methods.| ## FAQ 1. The database table exists, but no code file is generated, and the program does not report an error. * Configure database table names to be exactly the same as table names in the database. For example, when an H2 database creates a table with a script, the script name is written in lowercase, but the generated table name may be in upper case, so you need to configure the upper case table name here. 2. The problem "Table \[table_name] does not exist in database!!" when generating code for a multi-module project using the H2 database. * When the project structure is multi-module, the project structure is as follows: ````txt - project-parent - h2 - test.mv.db - project-child - src - main - java - resources - pom.xml(The code-generator-maven-plugin is configured here) - pom.xml(The project-parent's pom.xml) ```` * As you can see, the /h2/test.mv.db file is in the root path of the entire project * The URL configured in our program is jdbc:h2:file:./h2/test;AUTO_SERVER=TRUE;DB_CLOSE_ON_EXIT=FALSE;MODE=MYSQL * When using the code-generator-maven-plugin, the above URL cannot be configured because the root path of the plug-in in a multi-module project is project-child and is not where the /h2/test.mv.db file is located * At this point we can use the following two ways to manually specify: * Use absolute path: jdbc:h2:file:C:/Source/code/gitee/quickboot/h2/test;AUTO_SERVER=TRUE;DB_CLOSE_ON_EXIT=FALSE;MODE=MYSQL * Use relative paths (one more layer ../ symbol): jdbc:h2:file:./../h2/test;AUTO_SERVER=TRUE;DB_CLOSE_ON_EXIT=FALSE;MODE=MYSQL * Note: Only multi-module projects need to be specified this way; individual projects are not affected. ## Futures You are welcome to suggest better ways to improve this widget. ## Contributions You are welcome to contribute code, let more people more time to accompany the people you care about.