MyBatisgeneratorConfig自动生成代码总结

MBE中文文档:http://blog.csdn.net/poisions/article/details/51119386

1.下载插件

2.导包:mybatis-3.1.1.jar、mybatis-generator-core-1.3.2.jar、mybatis-spring-1.1.1.jar,这三个是工具包

3.导入MySql或者sqlServer包

4.

《第一种:Mysql数据库》

<?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>

<!--数据库驱动 -->
<context id="MySQLTables" targetRuntime="MyBatis3">
<commentGenerator>
<property name="suppressDate" value="true" />
<property name="suppressAllComments" value="true" />
</commentGenerator>


<!--数据库链接地址账号密码 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/zccd" userId="root"
password="123456">
</jdbcConnection>
<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>

<!--生成Model类存放位置 -->
<javaModelGenerator targetPackage="cn.jbit.model"
targetProject="MybatisGenerator\src">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator>

<!--生成映射文件存放位置 -->
<sqlMapGenerator targetPackage="cn.jbit.mapping"
targetProject="MybatisGenerator\src">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>

<!--生成Dao类存放位置 -->
<javaClientGenerator type="XMLMAPPER"
targetPackage="cn.jbit.mapper" targetProject="MybatisGenerator\src">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>

<!--生成对应表及类名 -->
<table tableName="student" domainObjectName="Student"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false"></table>
</context>
</generatorConfiguration>

《第二种:sqlServer数据库》

<?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>
<!--数据库驱动 -->
<context id="SQLServerTables" targetRuntime="MyBatis3">
<commentGenerator>
<property name="suppressDate" value="true" />
<property name="suppressAllComments" value="true" />
</commentGenerator>


<!--数据库链接地址账号密码 -->
<jdbcConnection driverClass="com.microsoft.sqlserver.jdbc.SQLServerDriver"
connectionURL="jdbc:sqlserver://localhost:1433;DatabaseName=contract" 
userId="sa" password="123456"> 
</jdbcConnection>
<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>

<!--生成Model类存放位置 -->
<javaModelGenerator targetPackage="cn.jbit.model"
targetProject="SQLserver MybatisGenerator\src">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator>

<!--生成映射文件存放位置 -->
<sqlMapGenerator targetPackage="cn.jbit.mapping"
targetProject="SQLserver MybatisGenerator\src">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>

<!--生成Dao类存放位置 -->
<javaClientGenerator type="XMLMAPPER"
targetPackage="cn.jbit.mapper" targetProject="SQLserver MybatisGenerator\src">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>

<!--生成对应表及类名 -->
<table tableName="staff" domainObjectName="Staff"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false"></table>
</context>
</generatorConfiguration>


5.选中xml文件右键,generator Mybatis/ibatis,

ok

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值