項(xiàng)目結(jié)構(gòu)
項(xiàng)目中如果使用關(guān)系型數(shù)據(jù)庫缚柏,配合ibatis使用挟鸠,只需要建立數(shù)據(jù)庫表就ok褐墅,其他的就交給插件去做了。
- 1.pom文件中添加
<build>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<configurationFile>${basedir}/src/main/resources/generator/generatorConfig.xml</configurationFile>
<overwrite>true</overwrite>
<verbose>true</verbose>
</configuration>
</plugin>
</plugins>
</build>
- 2.在resources中添加配置文件
resource
|____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" >
<!--使用方法:mvn mybatis-generator:generate-->
<generatorConfiguration>
<!--讀取配置文件地址-->
<properties resource="application-test.properties"/>
<!--連接驅(qū)動(dòng)要確定地址-->
<classPathEntry location="/Users/liuxin/Desktop/postgresql-42.0.0.jre6 2.jar"/>
<context id="context1" targetRuntime="MyBatis3Simple" defaultModelType="flat">
<property name="beginningDelimiter" value="`"/>
<property name="endingDelimiter" value="`"/>
<jdbcConnection driverClass="org.postgresql.Driver"
connectionURL="${druid.url}"
userId="${druid.username}"
password="${druid.password}">
</jdbcConnection>
<!--實(shí)體類也不用提前惜傲,建立,會(huì)自動(dòng)根據(jù)數(shù)據(jù)庫生成贝攒,對應(yīng)數(shù)據(jù)庫中字段-->
<javaModelGenerator targetPackage="pterosaur.account.domain" targetProject="src/main/java"/>
<!--映射的mapper.xml文件-->
<sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources"/>
<!--映射文件盗誊,目標(biāo)不必提前生成,會(huì)自動(dòng)生成-->
<javaClientGenerator targetPackage="pterosaur.account.mapper" targetProject="src/main/java"
type="XMLMAPPER"/>
<!--輸入表明,表名不用對應(yīng)實(shí)體哈踱,會(huì)自動(dòng)判斷-->
<table tableName="boluome_flow" ></table>
<table tableName="boluome_refund_flow"></table>
<table tableName="boluome_refund_seettlement"></table>
<table tableName="boluome_settlement"></table>
<table tableName="boss_settlement_account"></table>
<table tableName="boss_transaction_flow"></table>
<table tableName="settlement_account"></table>
<table tableName="user_settlement_account"></table>
<table tableName="user_transcation_flow"></table>
</context>
</generatorConfiguration>