idea使用mybaits generator
配置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> <classPathEntry location="E:\repository\com\oracle\ojdbc6\11.2.0.4.0\ojdbc6-11.2.0.4.0.jar" /> <!-- 生成上下文配置数据库连接和生成的对象--> <context id="accountCalculate" targetRuntime="MyBatis3">
<!--数据库配置-->
<jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver" connectionURL="" userId="" password=""> </jdbcConnection> <javaTypeResolver > <property name="forceBigDecimals" value="false" /> </javaTypeResolver> <!-- pojo生成配置--> <javaModelGenerator targetPackage="com.xquant.xqa.component.task.account.model" targetProject="F:\实习\dev\trunk\modules\java\xquant-xqa-component-task\src\main\java"> <property name="enableSubPackages" value="false" /> <property name="trimStrings" value="true" /> </javaModelGenerator> <-- mapper 文件配置--> <sqlMapGenerator targetPackage="sqlMapper.engine.account" targetProject="F:\实习\dev\trunk\modules\java\xquant-xqa-component-task\src\main\resources"> <property name="enableSubPackages" value="false" /> </sqlMapGenerator> <--对应的mapper接口配置--> <javaClientGenerator type="XMLMAPPER" targetPackage="com.xquant.xqa.component.task.account.dao" targetProject="F:\实习\dev\trunk\modules\java\xquant-xqa-component-task\src\main\java"> <property name="enableSubPackages" value="false" /> </javaClientGenerator> <table schema="xqa_trd" tableName="TXQA_RST_ACCT" > </table> <table schema="xqa_trd" tableName="TXQA_RST_ACCT_DETAI" > </table> <table schema="xqa_trd" tableName="TCRP_NAV" > </table> <table schema="xqa_trd" tableName="TCRP_HLD" > </table> </context> </generatorConfiguration>
配置文件中的targetproject指向磁盘中项目的位置,并且要具体到文件夹,不然会直接生成在项目下
配置项目pom.xml
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.xquant.xqa.component.parent</groupId> <artifactId>xquant-component-parent</artifactId> <version>1.0.0-SNAPSHOT</version> </parent> <groupId>com.xquant.xqa.component</groupId> <artifactId>xquant-xqa-component-task</artifactId> <version>1.0.0-SNAPSHOT</version> <name>xquant-xqa-component-task</name> <!-- FIXME change it to the project's website --> <url>http://www.example.com</url> <properties> <maven.test.skip>true</maven.test.skip> </properties> <dependencies> <dependency> <groupId>com.xquant.xqa.component</groupId> <artifactId>xquant-xqa-component-engine</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <version>1.3.2</version> <configuration> <!--配置文件的位置--> <configurationFile>src/main/resources/generatorConfig.xml</configurationFile> <verbose>true</verbose> <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.2</version> </dependency>
<!--添加数据库依赖是为了防止找不到数据库驱动类-->
<dependency> <groupId>com.oracle</groupId> <artifactId>ojdbc6</artifactId> <version>11.2.0.4.0</version> <scope>runtime</scope> </dependency> </dependencies> </plugin> </plugins> </build> </project>
添加maven运行项
working directory为项目所在位置
command line 为生成命令 -e -x为输出日志