Mybatis-generate 逆向工程
1. generate.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="D:\project_he\trunk\mios-chinamobile-sx-rest\mybatis-generator\lib\mysql-connector-java-5.1.29.jar" />
<context id="MySqlTables" targetRuntime="MyBatis3">
<property name="javaFileEncoding" value="utf-8" />
<property name="mergeable" value="true"></property>
<plugin type="org.mybatis.generator.plugins.RowBoundsPlugin"></plugin>
<plugin type="org.mybatis.generator.plugins.SerializablePlugin"></plugin>
<commentGenerator>
<!-- 如果你只生成一次代码,以后再不用工具生成可以关闭注释,如果会重复生成就要把注释开关打开。我的配置参数是打开时间注释 -->
<property name="suppressDate" value="false" />
<!-- 是否去除自动生成的注释 这个最好设置成false 否则容易出现重复代码 -->
<property name="suppressAllComments" value="false" />
</commentGenerator>
<!--数据库链接URL,用户名、密码 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://10.209.198.83:3306/emalldb" userId="emall"
password="emall">
</jdbcConnection>
<!--javaType解析器 -->
<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!-- 生成模型的包名和位置 -->
<javaModelGenerator targetPackage="com.sitech.boss.dao.model"
targetProject="src\main\java">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!-- 生成映射文件的包名和位置 -->
<sqlMapGenerator targetPackage="com.sitech.boss.dao.mapper"
targetProject="src\main\java">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<!-- 生成DAO接口的包名和位置 -->
<javaClientGenerator type="XMLMAPPER"
targetPackage="com.sitech.boss.dao.api"
targetProject="src\main\java">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
<!-- <table tableName="td_pcard_act_stall" domainObjectName="TdPcardActStall" enableCountByExample="false" -->
<!-- enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> -->
<!-- <property name="constructorBased" value="false" /> td_sign_repair_detail-->
<!-- </table> -->
<table tableName="all_prod_operate_log" domainObjectName="AllProdOperateLog" enableCountByExample="true"
enableUpdateByExample="true" enableDeleteByExample="false" enableSelectByExample="true" selectByExampleQueryId="false">
<property name="constructorBased" value="false" />
</table>
<!-- <table tableName="td_pcard_act" domainObjectName="TdPcardAct" enableCountByExample="false" -->
<!-- enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> -->
<!-- <property name="constructorBased" value="false" /> -->
<!-- </table> -->
</context>
</generatorConfiguration>
|
2.Maven配置
|
3. 使用方式
①在Eclipse 中:找到mybatis-generator文件夹->右键Run As->Run Configurations->Maven Build->New Configuration->Base directory->复制粘贴-X clean mybatis-generator:generate。 !记得在base directory 指向当前项目(亲身采坑)
②在IDEA 中使用maven插件
点击MavenProject->plugins 中的 mybatis-generate