KenhoMBGPlus SpringBoot模板生成工具(二)-参数前端交互设置

1.需求

KenhoMBGPlus期待的功能是通过传入参数可以指定数据库进行模板的新增。

2.问题分析

在开源代码中生成的表和相关信息是已经写在配置文件中,因此在工具中我们要使配置是可以通过用户自定义的,其次就是自定义的配置如何和配置文件相绑定。

3.解决问题

3.1 配置文件自定义

关于配置文件自定义,在前一篇博客KenhoMBGPlus SpringBoot模板生成工具(一)-构建项目中已经把源码修改为Spring Boot的启动形式,因此我们可以通过前端页面进行传参。查看源码我们能发现我们可以发现在ShellRunner中下面的代码段对我们传入的配置文件进行解析。

            ConfigurationParser cp = new ConfigurationParser(warnings);
            Configuration config = cp.parseConfiguration(configurationFile);

因此在分析之后我们对config部分参数进行重设置

        TableRelateDetail tableinfo = (TableRelateDetail) ThreadLocalUtil.get("tableinfo");
        JDBCConnectionConfiguration jdbcConnectionConfiguration = config.getContexts().get(0).getJdbcConnectionConfiguration();
        /**
         * 重新设置密码和账号
         */
        jdbcConnectionConfiguration.setPassword(tableinfo.getPassword());
        jdbcConnectionConfiguration.setUserId(tableinfo.getUsername());
        jdbcConnectionConfiguration.setConnectionURL("jdbc:mysql://" + tableinfo.getDatabaseurl() + "?characterEncoding=utf8&useSSL=false");
        jdbcConnectionConfiguration.setDriverClass("com.mysql.jdbc.Driver");
        /**
         * 重新设置服务包名
         */
        SqlMapGeneratorConfiguration sqlMapGeneratorConfiguration = config.getContexts().get(0).getSqlMapGeneratorConfiguration();
        sqlMapGeneratorConfiguration.setTargetPackage(tableinfo.getServerPackage());
        /**
         * 重新设置对象包名
         */
        JavaModelGeneratorConfiguration javaModelGeneratorConfiguration = config.getContexts().get(0).getJavaModelGeneratorConfiguration();
        javaModelGeneratorConfiguration.setTargetPackage(tableinfo.getObjectPackage());
        /**
         * 设置表名
         */
        TableConfiguration tableConfiguration = config.getContexts().get(0).getTableConfigurations().get(0);
        tableConfiguration.setTableName(tableinfo.getTableName());
        tableConfiguration.setDomainObjectName(tableinfo.getObjectName());

实现前端配置指定生成对象

下一篇博文我会通过源码构成文件的代码结合FreeMark实现我们的最终目标。

github:https://github.com/tale2009/KenhoMBGPlus

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值