全栈小白的gravatar头像
全栈小白 2023-03-16 16:02:31
Mybatis-Plus 开发提速器,快来了解一下吧

原创声明:本人所发内容及涉及源码,均为亲手所撸,如总结内容有误,欢迎指出

唠嗑部分

关于在实际开发中数据库表的实体类、mapper接口、映射文件等等,我想没有人自己写吧,毕竟没有任何技术含量。

现在常用的数据库逆向工程有很多,如mybatis插件、idea插件、mybatis-plus等等,但是今天小白给大家带来的是Web UI的方式。

mybatis-plus-generator-ui提供交互式的Web UI用于生成兼容mybatis-plus框架的相关功能代码

包括Entity,Mapper,Mapper.xml,Service,Controller等 ,可以自定义模板以及各类输出参数,也可通过SQL查询语句直接生成代码。

开源地址: https://github.com/davidfantasy/mybatis-plus-generator-ui

如何使用

创建工程&导入依赖

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>com.baomidou</groupId>
        <artifactId>mybatis-plus-boot-starter</artifactId>
        <version>3.0.5</version>
    </dependency>
    <dependency>
        <groupId>com.github.davidfantasy</groupId>
        <artifactId>mybatis-plus-generator-ui</artifactId>
        <version>2.0.0</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.47</version>
    </dependency>
</dependencies>

mybatis-plus-generator-ui的依赖,cope只需要写test就可以了,我们在test运行

在项目的test目录新建一个启动类,代码示例如下:

/**
 * @Project: mybatis-plus-generator-ui-demo
 * @Author: cxs2014501@163.com
 * @Create: 2023/2/24 14:21
 * @Description:
 **/
public class GeberatorUIServer {
    public static void main(String[] args) {
        GeneratorConfig config = GeneratorConfig.builder().jdbcUrl("jdbc:mysql://10.10.10.10:3306/mybatis-plus-generator-ui-demo")
                .userName("root")
                .password("root")
                .driverClassName("com.mysql.jdbc.Driver")
                //数据库schema,POSTGRE_SQL,ORACLE,DB2类型的数据库需要指定
                .schemaName("myBusiness")
                //如果需要修改entity及其属性的命名规则,以及自定义各类生成文件的命名规则,可自定义一个NameConverter实例,覆盖相应的名称转换方法,详细可查看该接口的说明:
                .nameConverter(new NameConverter() {
                    /**
                     * 自定义Service类文件的名称规则
                     */
                    @Override
                    public String serviceNameConvert(String tableName) {
                        return this.entityNameConvert(tableName) + "Service";
                    }
​
                    /**
                     * 自定义Controller类文件的名称规则
                     */
                    @Override
                    public String controllerNameConvert(String tableName) {
                        return this.entityNameConvert(tableName) + "Controller";
                    }
                })
                //所有生成的java文件的父包名,后续也可单独在界面上设置
                .basePackage("com.cxs")
                .port(8086)
                .build();
        MybatisPlusToolsApplication.run(config);
    }
}

GeneratorConfig还包含一些基本的配置参数以及各个可扩展的接口,比如自定义模板参数,具体的说明可查看源码注释。

运行该启动类,启动一个Generator Server。然后访问http://localhost:8068即可进入到管理界面。

Mybatis-Plus 开发提速器,快来了解一下吧

访问:localhost:8086

Mybatis-Plus 开发提速器,快来了解一下吧

输出文件的配置 :内置Entity,Mapper,Service,Controller等6种类型代码的模板配置,可以上传模板进行替换,并修改各类参数,配置参数已经按照影响的文件类型重新进行了分类,并加入了部分文本说明;也可以自行添加其它类型的自定义输出文件。所有的配置项都会按照项目包名进行保存,只需一次性设置就可以了。

Mybatis-Plus 开发提速器,快来了解一下吧

Mybatis-Plus 开发提速器,快来了解一下吧

选择一张表,点击生成,可以设置作者信息、是否覆盖原文件,生成文件的种类等等

Mybatis-Plus 开发提速器,快来了解一下吧

结果

Mybatis-Plus 开发提速器,快来了解一下吧

你以为就这点嘛,哈哈,还可以支持sql生成,我们来看看

注意:动态参数用''引起来

Mybatis-Plus 开发提速器,快来了解一下吧

填写配置项

Mybatis-Plus 开发提速器,快来了解一下吧

xml配置文件都帮我们生成了,还可以生成复杂的SQL

Mybatis-Plus 开发提速器,快来了解一下吧


打赏

已有1人打赏

最代码官方的gravatar头像
最近浏览
流水本无情  LV9 3月13日
80730176  LV7 2月19日
笨小孩一号  LV22 1月16日
半夏bx  LV14 1月7日
3334004690  LV3 2023年10月31日
newhaijun  LV15 2023年9月21日
wanglongfei2  LV2 2023年9月5日
543539666  LV7 2023年8月21日
 LV6 2023年8月21日
damowang0022 2023年8月18日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友