# mybatis-plus-generator-ui **Repository Path**: zky10/mybatis-plus-generator-ui ## Basic Information - **Project Name**: mybatis-plus-generator-ui - **Description**: 对mybatis-plus-generator进行封装,通过Web UI快速生成兼容Spring boot,mybatis-plus框架的各类业务代码(新增mybatis一对一,一对多代码生成功能) - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 105 - **Created**: 2021-09-02 - **Last Updated**: 2021-09-02 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## mybatis-plus-generator-ui 提供交互式的Web UI用于生成兼容mybatis-plus框架的相关功能代码,包括Entity,Mapper,Mapper.xml,Service,Controller等 ,可以自定义模板以及各类输出参数,也可通过SQL查询语句直接生成代码。 ## 新增功能 通过自定义了一套DSL(类 graphql 语法 + 简单sql语法),实现添加一对一,一对多代码生成功能,支持生成 支持原条件查询转换功能 - controller - mapper - resultMapper - select DSL示例 ```sql select findByRootIdOrClassId(type:"vip.youngboy.test.model.TplClass") { b.id Long, b.class_name:className String, b.p_name:pName String, c.rootId Long, components.config(type:"vip.youngboy.test.model.TemplateModuleInfo",fetch:"list"){ a.id Long, a.component:component String, a.name String, a.page_type:pageType String, a.thumbnail String, a.range_index:rangeIndex Integer } } from tpl_class_info b JOIN tpl_class_rel c ON b.id = c.classId JOIN template_module_info a ON a.id = c.modId ``` 解析器项目地址 [https://gitee.com/youngboyvip/graphqljs](https://gitee.com/youngboyvip/graphqljs) 效果图预览 ![解析ast](imgs/oast.png) ![代码生成配置](imgs/astconfig.png) ## 使用方法 1. 打包 打包前端 ```cmd cd src/frontend npm install npm run build ``` 打包后台 ```cmd mvn intall ``` 2. 找到target目录,运行install.cmd添加到系统环境变量 3. 在项目根目录新建`pui.yml`,指定数据库信息 ```yaml username: xxx password: xxx driver: com.mysql.cj.jdbc.Driver jdbcUrl: jdbc:mysql://localhost:1231/xxx?characterEncoding=utf-8&useSSL=false&servertimezone=cst basePackage: vip.youngboy ``` 4. 在项目目录命令行输入`pui` ,启动完成后访问系统页面 默认端口 8063 ## 主要功能 1. **数据表的查询和浏览**:可以直接浏览和查询配置的数据源的数据表信息,可选择一个或多个生成模板代码: ![数据表查询](https://gitee.com/davidfantasy/mybatis-plus-generator-ui/raw/master/imgs/table-list.png) 2. **输出文件的配置**:内置Entity,Mapper,Service,Controller等6种类型代码的模板配置,可以上传模板进行替换,并修改各类参数,配置参数已经按照影响的文件类型重新进行了分类,并加入了部分文本说明;也可以自行添加其它类型的自定义输出文件。所有的配置项都会按照项目包名进行保存,只需一次性设置就可以了。 ![输出文件类型配置](https://gitee.com/davidfantasy/mybatis-plus-generator-ui/raw/master/imgs/output-config.png) ![文件输出选项配置](https://gitee.com/davidfantasy/mybatis-plus-generator-ui/raw/master/imgs/strategy.png) 3. **代码生成选项**:将每次生成代码时可能变动的内容加入到代码生成选项中,方便调整每次的生成策略,比如:是否覆盖原文件,生成文件的种类等等: ![代码生成选项](https://gitee.com/davidfantasy/mybatis-plus-generator-ui/raw/master/imgs/generator-options.png) 4. **SQL结果集自动生成代码**:通过输入查询SQL,可自动在Mapper(Xml及Java)中生成对应的查询方法,DTO对象和ResultMap(结果集映射配置) ![SQL编辑](https://gitee.com/davidfantasy/mybatis-plus-generator-ui/raw/master/imgs/SQL-edit.png) ![SQL代码生成选项](https://gitee.com/davidfantasy/mybatis-plus-generator-ui/raw/master/imgs/SQL-generator-options.png) 5. **动态SQL增强**:自动识别含有mybatis动态参数的where条件,转换为mybatis的动态SQL条件 ![动态SQL增强](https://gitee.com/davidfantasy/mybatis-plus-generator-ui/raw/master/imgs/dynamicsql.png) ## 常见问题 **Q:下载源码中怎么直接运行?** **不建议直接下载源码运行**,该项目是设计为直接嵌入到对应的业务项目中使用,可以自动识别项目路径等环境变量。如需采用源码运行,需要另行编译src\frontend中的静态资源(源码中不包含已编译的页面),在src\frontend文件夹中执行: ~~~shell yarn install yarn run build ~~~ 然后修改src\test\java\TestApplication中数据库的相关配置,并运行。 **Q:支持哪些类型的数据库?** 支持几乎所有主流的数据库,具体可参考mybatis-plus-generator框架的文档。需要自行引入数据库的driver包,并在 GeneratorConfig中指定driverClassName。 **Q:怎么自定义模板参数?** 在GeneratorConfig中自定义TemplateVaribleInjecter,返回需要在模板中使用的参数,例如: ```java GeneratorConfig config = GeneratorConfig.builder() .templateVaribleInjecter(new TemplateVaribleInjecter() { @Override public Map getCustomTemplateVaribles(TableInfo tableInfo) { Map params = new HashMap<>(); return params; } }) ``` **Q:保存的配置是存储到什么地方的?** 所有的用户保存的配置是按照basePackage分组保存到user.home目录的.mybatis-plus-generator-ui中的,不同项目的配置不会互相影响。