- github - https://github.com/mybatis/generator
- doc - http://mybatis.org/generator/
- quick start - http://mybatis.org/generator/quickstart.html#MyBatis3Simple
why?
how
看文檔把。。
<!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="simple" targetRuntime="MyBatis3Simple">
<!-- 指定如何連到目標數據庫 -->
<!-- 要改 --><jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="xxxx?useUnicode=true&characterEncoding=utf-8"
password="xxx"
userId="xxx"/>
<!-- 類型解析器 -->
<javaTypeResolver>
<!-- When the property is true,
the Java type resolver will always use java.math.BigDecimal
if the database column is of type DECIMAL or NUMERIC. -->
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver>
<!-- 定義javaBean的生成策略
targetPackage 目標包名
targetProject 目標工程
-->
<!-- 要改 --><javaModelGenerator targetPackage="com.bibi.generator.bean" targetProject="src/main/java">
<property name="enableSubPackages" value="true"/><!-- 包含子包 -->
<property name="trimStrings" value="true"/><!-- When true, MyBatis Generator will insert code to trim character fields. -->
</javaModelGenerator>
<!-- sql映射生成策略 -->
<!-- 要改 --><sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources">
<property name="enableSubPackages" value="true"/><!-- 包含子包 -->
</sqlMapGenerator>
<!-- 指定mapper接口所在的位置 -->
<!-- 要改 --><javaClientGenerator type="XMLMAPPER" targetPackage="com.bibi.generator.dao" targetProject="src/main/java">
<property name="enableSubPackages" value="true"/><!-- 包含子包 -->
</javaClientGenerator>
<!-- 指定要逆向分析哪些表:根據要創建javaBean -->
<table tableName="user" domainObjectName="User"></table>
<table tableName="user_state" domainObjectName="UserState"></table>
</context>
</generatorConfiguration>