MyBatis Generator
一.
下载 mybatis-generator-core-1.3.2.jar 以及 mysql-connector-java-5.1.26
下载地址: http://pan.baidu.com/s/1tlrx8
二.
配置文件 generator.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="mysql-connector-java-5.1.26.jar" />
<context id="MySQL" defaultModelType="flat" targetRuntime="MyBatis3">
<commentGenerator>
<!-- 是否去除自动生成的注释 true:是 : false:否 -->
<property name="suppressAllComments" value="true" />
</commentGenerator>
<!-- 数据库连接信息:驱动类、URL、用户名、密码 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/mms" userId="root" password="root"></jdbcConnection>
<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!-- 生成模型的包名和位置 -->
<javaModelGenerator targetPackage="com.letv.mms.po" targetProject="E:\mms-common\src\main\java">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!-- 生成的映射文件包名和位置 -->
<sqlMapGenerator targetPackage=" MyBatis" targetProject="E:\mms-common\src\main\resources">
<property name="enalbeSubPackages" value="true" />
</sqlMapGenerator>
<!-- 生成DAO的包名和位置 -->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.letv.mms.dao" targetProject="E:\mms-common\src\main\java">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
<!-- 要生成哪此表(更改tableName和domainObjectName就可以) -->
<table tableName="t_video_info" domainObjectName="VideoPO" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table tableName="t_album_info" domainObjectName="AlbumPO" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table tableName="t_category_info" domainObjectName="CategoryPO" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table tableName="t_property_info" domainObjectName="PropertyPO" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table tableName="t_mms_info" domainObjectName="MmsPO" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
</context>
</generatorConfiguration>
几个注意事项:
1.生成路径请勿用中文,可能会有warning xxx does not exist
2.targetPackage不可为空 异常:SQLMapGenerator Target Package is Required for context
3.如遇其他问题可查看Mybatis官方文档 <generatorConfiguration>标签
三.运行脚本
java -jar mybatis-generator-core-1.3.2.jar -configfile generator.xml -overwrite
注意路径问题 建议将Mybatis与MySQL的jar包放在同一文件夹下。