mybatis自动生成java mapper xml
1.maven插件依赖
<plugin>
<!--Mybatis-generator插件,用于自动生成Mapper和POJO-->
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.7</version>
<configuration>
<configurationFile>../。。/generatorConfig-postgresql.xml</configurationFile>
<verbose>true</verbose>
<skip>true</skip>
<overwrite>true</overwrite>
</configuration>
<executions>
<execution>
<id>Generate MyBatis Artifacts</id>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.7</version>
</dependency>
</dependencies>
</plugin>
2.生成文件名generatorConfig-postgresql.xml
<?xml version="1.0" encoding="UTF-8"?><!-- 数据库的JDBC驱动的jar包地址 location是相对路径,是mybatis-generator插件所在模块的相对路径-->
<classPathEntry
location="../ex-config/postgresql-42.2.5.jar" />
<!-- 引入外部的数据源配置信息 -->
<!-- <properties resource="<dir>/oracle.properties" /> -->
<context id="postgresqlTables" targetRuntime="MyBatis3">
<!-- 生成的Java文件的编码 -->
<property name="javaFileEncoding" value="UTF-8"/>
<!-- 插件配置 -->
<plugin type="org.mybatis.generator.plugins.EqualsHashCodePlugin"></plugin>
<plugin type="org.mybatis.generator.plugins.SerializablePlugin"></plugin>
<plugin type="org.mybatis.generator.plugins.ToStringPlugin"></plugin>
<!-- 配置注释生成器 -->
<commentGenerator>
<!-- 是否去除自动生成的时间标志 -->
<property name="suppressDate" value="true"/>
<!-- 是否去除自动生成的注释 -->
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<!-- 数据库连接信息 -->
<jdbcConnection
driverClass="org.postgresql.Driver"
connectionURL="jdbc:postgresql://10.59.97.10:5432/almbi"
userId="almbidata"
password="almbi123" />
<!--指定生成的类型为java类型,避免数据库中number等类型字段 -->
<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!--自动生成的实体的存放包路径 固定存放公共模块-->
<javaModelGenerator targetPackage="com.pingan.almbi.common.model"
targetProject="../../almbi-common/src/main/java">
<property name="enableSubPackages" value="true" />
<!-- <property name="trimStrings" value="true" /> -->
</javaModelGenerator>
<!--src/main/resources src/main/java是mybatis-generator插件所在模块的相对路径-->
<!--自动生成的*Mapper.xml文件存放路径 -->
<sqlMapGenerator targetPackage="mapper.postgresql"
targetProject="src/main/resources">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<!--自动生成的*Mapper.java存放路径 -->
<javaClientGenerator targetPackage="com.pingan.almbi.mapper" type="XMLMAPPER"
targetProject="src/main/java">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
<!-- 需要生成的表 -->
<table tableName="bi_upload_log_info"
domainObjectName="BiUploadLogInfo2"
enableCountByExample="false"
enableUpdateByExample="false"
enableDeleteByExample="false"
enableSelectByExample="false"
selectByExampleQueryId="false">
<!-- <generatedKey column="ID" sqlStatement="select uuid_short()"
identity="false" /> -->
</table>
</context>
3.下载对应的驱动