Maven mybatis-generator自动生成代码

mybatis-generator可以自动生成代码,不管你是否喜欢它生成的代码的风格,它确实有助于我们更快速便捷的生成代码。

Maven pom文件配置:

<build>
<pluginManagement>
<plugins>
<plugin> <!-- Run mvn mybatis-generator:generate to use. -->
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>${mybatis-generator.version}</version>
<configuration>
<configurationFile>src/main/resources/mapping/generatorConfig.xml</configurationFile>
<overwrite>true</overwrite>
</configuration>
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>${ojdbc6.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>Generate MyBatis Artifacts</id>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
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="mysqlTables" targetRuntime="MyBatis3" defaultModelType="flat">
<!-- 是否去除自动生成的注释 -->
<commentGenerator>
<property name="suppressAllComments" value="true" />
<property name="suppressDate" value="true" />
</commentGenerator> <!-- 数据库连接的信息 -->
<jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver"
connectionURL="jdbc:oracle:thin:@(description=(address = ( protocol = tcp)(host=ip)(port=port))(connect_data=(SERVER=DEDICATED)(SERVICE_NAME=数据库)))"
userId="帐号" password="密码"/>
<javaTypeResolver>
<!-- false:JDBC DECIMAL、NUMERIC类型解析为Integer,默认方式 -->
<!-- true: JDBC DECIMAL、NUMERIC类型解析为java.math.BigDecimal -->
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver> <!-- 生成模型的包名和位置 -->
<javaModelGenerator targetPackage="com.pingan.bloan.bloan_flow.pojo.rcpmdata" targetProject="src/main/java"> <!-- 是否让schema作为包的后缀 -->
<property name="enableSubPackages" value="true"/>
<!-- 从数据库返回的值被清理前后的空格 -->
<property name="trimStrings" value="true"/>
</javaModelGenerator> <!-- 生成映射文件的包名和位置 -->
<sqlMapGenerator targetPackage="mapping/rcpmdata" targetProject="src/main/resources">
<property name="enableSubPackages" value="true"/>
</sqlMapGenerator> <!-- 生成DAO的包名和位置 --> <javaClientGenerator targetPackage="com.pingan.bloan.bloan_flow.dao.rcpmdata" targetProject="src/main/java" type="XMLMAPPER">
<property name="enableSubPackages" value="true"/>
</javaClientGenerator> <!-- 数据库表 -->
<table tableName="INV_EDOC_SIGN" domainObjectName="EDocSignPojo" enableUpdateByPrimaryKey = "true" enableCountByExample="false" enableUpdateByExample="false"-->
<!--enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
</context> </generatorConfiguration>

然后,你就可以在pom文件上右键,Run Maven,输入命令:mvn mybatis-generator:generate,即可自动生成代码了

上一篇:windows10开启hyper-v虚拟化


下一篇:iOS JavaScriptCore与H5交互时出现异常提示