【问题标题】:Table name not mapped to camel case by Mybatis GeneratorMybatis Generator 未将表名映射到驼峰式大小写
【发布时间】:2018-07-30 18:33:02
【问题描述】:

我试用了 Mybatis Generator,效果很好。但是,即使列名正确映射为驼峰式大小写,文件名(Mapper.xml、Client 和 Model)也不遵循驼峰式大小写。

因此,例如,表 TIPO_SERVICO 被映射到 Tiposervico/TipoServicoMapper 而不是 TipoServico/TipoServicoMapper。

我查看了 Mybatis Generator 文档,没有找到与表名大小写相关的属性。

附:我的数据库是 Oracle。

我的 generatorConfig.xml:

<?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>
    <context id="context" targetRuntime="MyBatis3Simple">
        <commentGenerator>
            <property name="suppressAllComments" value="true"/>
        </commentGenerator>

        <jdbcConnection userId="[USER]" password="[PASSWORD]" driverClass="oracle.jdbc.OracleDriver" connectionURL="jdbc:oracle:thin:@[IP]:1521:[ENV]">
            <property name="remarksReporting" value="true"/>
        </jdbcConnection>

        <javaTypeResolver>
            <property name="forceBigDecimals" value="false"/>
        </javaTypeResolver>

        <javaModelGenerator targetPackage="com.model" targetProject="src/main/java">
            <property name="enableSubPackages" value="false"/>
            <property name="trimStrings" value="true"/>
        </javaModelGenerator>

        <sqlMapGenerator targetPackage="com.mapper" targetProject="src/main/resources/META-INF">
            <property name="enableSubPackages" value="false"/>
        </sqlMapGenerator>

        <javaClientGenerator targetPackage="com.mapper" type="XMLMAPPER" targetProject="src/main/java">
            <property name="enableSubPackages" value="false"/>
        </javaClientGenerator>

        <table schema="patr" tableName="%" enableCountByExample="true" enableDeleteByExample="false"
               enableSelectByExample="true" enableUpdateByExample="false" >
            <domainObjectRenamingRule searchString="^Scm" replaceString="" />
        </table>
    </context>
</generatorConfiguration>

【问题讨论】:

    标签: mybatis mybatis-generator


    【解决方案1】:

    为什么不手动配置呢?添加 domainObjectName

    的属性
        <table schema="patr" tableName="TIPO_SERVICO" domainObjectName ="TipoServico" enableCountByExample="true" enableDeleteByExample="false"
               enableSelectByExample="true" enableUpdateByExample="false" >
            <domainObjectRenamingRule searchString="^Scm" replaceString="" />
        </table>
    

    【讨论】:

    • 我不使用 domainObjectName 因为我用它来为几十个表生成代码。但是,在我评论 domainObjectRenamingRule 之后,骆驼案例命名又开始起作用了。
    【解决方案2】:

    骆驼案例命名在评论 domainObjectRenamingRule 后再次起作用。

    【讨论】:

      猜你喜欢
      • 2017-06-13
      • 1970-01-01
      • 1970-01-01
      • 2013-07-11
      • 1970-01-01
      • 1970-01-01
      • 2011-02-27
      • 1970-01-01
      相关资源
      最近更新 更多