MyBatis Generator PostgreSQL逆向生成 区分大小写敏感
PostgreSQL使用说明区分大小写敏感
PostgreSQL对所有数据库标识符(表名,模式名,列名等)区分大小写。此外,PostgreSQL对所有小写字母的所有标识符都有不同的偏好。如果您使用PostgreSQL的所有小写标识符,那么MyBatis Generator将找到表并写入正确的SQL,而无需额外考虑。如果您使用混合的套件或大写标识符,则需要适当地配置MyBatis Generator:如果您的表或模式是混合大小写或全部大小写,请使用delimitIdentifiers选项。对于每个混合大小写或大写列,您可以指定一个元素来专门分隔列,也可以指定delimitAllColumns属性来分隔所有列名。例子:
<table schema="HR" tableName="Employees"
delimitIdentifiers="true" delimitAllColumns="true"/>
或者:
<table schema="HR" tableName="Employees" delimitIdentifiers="true" >
<columnOverride column="EmployeeId" delimitedColumnName="true" />
<columnOverride column="EmployeeName" delimitedColumnName="true" />
</table>
generatorConfig.xml
<?xml version="1.0" encoding="UTF-8"?> <!-- 不生成注释 -->
<commentGenerator>
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<!-- JDBC -->
<jdbcConnection driverClass="org.postgresql.Driver"
connectionURL="jdbc:postgresql://xx"
userId="xx"
password="@1234"/>
<javaTypeResolver type="com.cnpc.epai.mybatis.generator.JavaTypeResolverEnhancer">
<!-- 是否强制转换Decimal或number域为java的BigDecimal -->
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!-- 生成的 java pojo 位置,targetProject可以写fs位置 -->
<javaModelGenerator targetPackage="xx.pojo" targetProject="src/main/java">
<property name="enableSubPackages" value="false" />
<!-- setter方法是否过滤空字符 -->
<property name="trimStrings" value="false" />
</javaModelGenerator>
<!-- 生成的映射 xml 位置 -->
<sqlMapGenerator targetPackage="xx.mapper" targetProject="src/main/java">
<property name="enableSubPackages" value="false" />
</sqlMapGenerator>
<!-- 生成映射 mapper 接口位置 -->
<javaClientGenerator type="XMLMAPPER" targetPackage="xx.mapper" targetProject="src/main/java">
<property name="enableSubPackages" value="false" />
</javaClientGenerator>
<!-- 需要自动逆向生成代码的表 -->
<table schema="exp" tableName="xx" domainObjectName="xx"
enableCountByExample="false"
enableUpdateByExample="false"
enableDeleteByExample="false"
enableSelectByExample="false"
selectByExampleQueryId="false" >
<property name="useActualColumnNames" value="false" />
<columnOverride column="LONG_VARCHAR_FIELD" jdbcType="VARCHAR" />
</table>
</context>
命令行 输入 mvn mybatis-generator:generate 自动生成