Table 名称未通过 Mybatis Generator 映射到驼峰式大小写
Table name not mapped to camel case by Mybatis Generator
我试用了 Mybatis Generator,效果很好。但是,即使列名正确映射为驼峰式大小写,文件名(Mapper.xml、客户端和模型)也没有遵循驼峰式大小写。
因此,例如,table TIPO_SERVICO 被映射到 Tiposervico/TiposervicoMapper 而不是 TipoServico/TipoServicoMapper。
我检查了 Mybatis Generator 文档,但没有找到与 table 名称大小写相关的 属性。
P.s。我的数据库是 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>
为什么不手动配置呢?添加 domainObjectName
的属性
<table schema="patr" tableName="TIPO_SERVICO" domainObjectName ="TipoServico" enableCountByExample="true" enableDeleteByExample="false"
enableSelectByExample="true" enableUpdateByExample="false" >
<domainObjectRenamingRule searchString="^Scm" replaceString="" />
</table>
在对 domainObjectRenamingRule 进行评论后,驼峰式命名再次起作用。
我试用了 Mybatis Generator,效果很好。但是,即使列名正确映射为驼峰式大小写,文件名(Mapper.xml、客户端和模型)也没有遵循驼峰式大小写。
因此,例如,table TIPO_SERVICO 被映射到 Tiposervico/TiposervicoMapper 而不是 TipoServico/TipoServicoMapper。
我检查了 Mybatis Generator 文档,但没有找到与 table 名称大小写相关的 属性。
P.s。我的数据库是 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>
为什么不手动配置呢?添加 domainObjectName
的属性 <table schema="patr" tableName="TIPO_SERVICO" domainObjectName ="TipoServico" enableCountByExample="true" enableDeleteByExample="false"
enableSelectByExample="true" enableUpdateByExample="false" >
<domainObjectRenamingRule searchString="^Scm" replaceString="" />
</table>
在对 domainObjectRenamingRule 进行评论后,驼峰式命名再次起作用。