您的位置:首页 > 其它

MyBatis Generator的基础使用

2015-06-26 12:35 225 查看
参考自:MyBatis 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:\j2ee_workspace\Mybatis_Generator\lib\mysql-connector-java-5.1.27.jar" />

<context id="MySQLTables" targetRuntime="MyBatis3">
<commentGenerator>
<!-- 不需要注释 -->
<property name="suppressAllComments" value="true"/>
</commentGenerator>

<!-- 数据库连接 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://xxx.xxx.xxx.xxx:xxxx/xxx"
userId="xxx"
password="password">
</jdbcConnection>

<javaTypeResolver >
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>

<!-- 实体类 -->
<javaModelGenerator targetPackage="com.nicchagil.model" targetProject="E:\j2ee_workspace\Mybatis_Generator\src">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator>

<!-- 映射关系、标准化的动态SQL文件 -->
<sqlMapGenerator targetPackage="com.nicchagil.mapping"  targetProject="E:\j2ee_workspace\Mybatis_Generator\src">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>

<!-- DAO -->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.nicchagil.dao"  targetProject="E:\j2ee_workspace\Mybatis_Generator\src">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>

<!-- 需转换的表,及相关配置。(默认生成全部标准动态SQL,这个将几个本人不用的设置为false,不生成。) -->
<table tableName="T_USER" domainObjectName="User" enableSelectByExample="false" enableDeleteByExample="false"
enableCountByExample="false" enableUpdateByExample="false" selectByExampleQueryId="false">
<!-- 使用驼峰式属性命名 -->
<property name="useActualColumnNames" value="false"/>
</table>

</context>
</generatorConfiguration>


下载

MyBatis Generator包(mybatis-generator-core-1.3.2.jar)

MySQL的驱动包(mysql-connector-java-5.1.27.jar)

-

运用命令生成代码(此命令为覆盖原先的同名代码)

java -jar mybatis-generator-core-1.3.2.jar -configfile generatorConfig.xml -overwrite


不想覆盖,则此命令

java -jar mybatis-generator-core-1.3.2.jar -configfile generatorConfig.xml
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息