SpringBoot(五):多模块项目Generator生成代码

栏目: Java · 发布时间: 6年前

内容简介:本作品采用本文作者:低调小熊猫文章链接:

本作品采用 知识共享署名 4.0 国际许可协议 进行许可。

本文作者:低调小熊猫

文章链接: https://aodeng.cc/archives/springbootwu

转载声明:自由转载-非商用-非衍生-保持署名,非商业转载请注明作者及出处,商业转载请联系作者本人qq:2696284032

多模块项目Generator生成代码

简单的代码生成可以参考我的上一篇文章

SpringBoot(二):代码生成器Generator

项目结构

SpringBoot(五):多模块项目Generator生成代码

我们需要将生成的代码放在hope-core中,在hope-admin里面使用,这样分层比较好

在hope-core模块下面配置插件

<!-- SpringBoot mybatis generator插件-->
            <plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>1.3.5</version>
                <configuration>
                    <configurationFile>${project.basedir}/src/main/resources/generator/generatorConfig.xml</configurationFile>
                    <verbose>true</verbose>
                    <overwrite>true</overwrite>
                </configuration>
            </plugin>

在hope-core模块下面创建generator文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
        PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
        "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
    <classPathEntry
            location="C:\z_java_resources\apache-maven-repo\mysql\mysql-connector-java\5.1.34\mysql-connector-java-5.1.34.jar" />
    <context id="Mysql" targetRuntime="MyBatis3Simple" defaultModelType="flat">
        <property name="beginningDelimiter" value="`"/>
        <property name="endingDelimiter" value="`"/>

        <!--我不喜欢自动生成的注解-->
        <commentGenerator>
            <property name="suppressDate" value="true"/>
            <property name="suppressAllComments" value="true" />
        </commentGenerator>

        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                        connectionURL="jdbc:mysql://localhost:3306/hope"
                        userId="root"
                        password="123456">
        </jdbcConnection>

        <!--生成Model类存放位置-->
        <javaModelGenerator targetPackage="com.ad.core.hope.model" targetProject="C:/Users/ad182/Desktop/sb2.0/hope/hope-core/src/main/java"></javaModelGenerator>
        <!--生成映射文件存放位置-->
        <sqlMapGenerator targetPackage="mapper" targetProject="C:/Users/ad182/Desktop/sb2.0/hope/hope-core/src/main/resources"></sqlMapGenerator>
        <!--生成Dao类存放位置-->
        <javaClientGenerator type="XMLMAPPER" targetPackage="com.ad.core.hope.service" targetProject="C:/Users/ad182/Desktop/sb2.0/hope/hope-core/src/main/java"></javaClientGenerator>
        <!--链接的数据库全表生成-->
<!--        <table tableName="%">
            <generatedKey column="id" sqlStatement="Mysql" identity="true"/>
        </table>-->
        <!--自定义代码生成,建议写好一个直接复制-->
        <table  tableName="%"
                enableCountByExample="false"
                enableDeleteByPrimaryKey="false"
                enableDeleteByExample="false"
                enableInsert="false"
                enableSelectByExample="false"
                enableUpdateByExample="false"
                enableUpdateByPrimaryKey="false">
        <!--实体类驼峰命名-->
        <property name="useActualColumnNames" value="false"/>
        <!-- mysql配置 -->
        <generatedKey column="id" sqlStatement="Mysql" identity="true"/>
        </table>
    </context>
</generatorConfiguration>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

移动风暴

移动风暴

[美]弗雷德·沃格尔斯坦 / 朱邦芊 / 中信出版社 / 2014-1-1 / 39

也许,除了伟大的乔布斯,每一位奋力改变世界的硅谷英雄,都值得我们肃然起敬。苹果与谷歌十年博弈,关于这场移动平台战争的报道早已铺天盖地,而这是第一次,我们能听到幕后工程师的真实声音。两大科技巨人用智能手机和平板电脑颠覆了电脑产业。它们位处变革的中心,凭借各自的经营哲学、魅力领袖和商业敏感度,把竞争变成了残酷对决。商业记者沃格尔斯坦报道这场对抗已逾十载,在《移动风暴》中,他带领我们来到一间间办公室和会......一起来看看 《移动风暴》 这本书的介绍吧!

URL 编码/解码
URL 编码/解码

URL 编码/解码

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换