您的位置:首页 > 移动开发

Mybatis自动生成Mapper工具配置文件

2012-08-31 10:20 465 查看
<?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.jar" />

<context id="context1" >

<commentGenerator>

<!-- 避免生成注解 -->

<property name="suppressAllComments" value="true" />

</commentGenerator>

<!-- 数据库连接信息 -->

<jdbcConnection driverClass="com.mysql.jdbc.Driver"

connectionURL="jdbc:mysql://localhost/test"

userId="root" password="admin" />

<!-- Model文件保存位置 -->

<javaModelGenerator targetPackage="com.metarnet.DAO.Model" targetProject="src/model" />

<!-- 生成的mapper文件 -->

<sqlMapGenerator targetPackage="com.metarnet.DAO.Mapper" targetProject="src/xml" />

<!-- 生成的查询条件的类 -->

<javaClientGenerator targetPackage="com.metarnet.DAO.Mapper" targetProject="src/mapper" type="XMLMAPPER" />

<!-- 需要连接的表 -->

<table tableName="test" />

</context>

</generatorConfiguration>

调用方法:下载mybatis-generator,数据库驱动 到文件夹下,编写配置文件MYSQL.xml(以上内容),使用命令生成即可

@echo OFF

@ECHO =======================Mybatis自动生成中...=======================

java -jar mybatis-generator.jar -configfile MYSQL.xml -overwrite

pause

追加一个配置文件

<?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="ojdbc14.jar" />

<context id="context1" targetRuntime="MyBatis3">

<commentGenerator>

<!-- 避免生成注解 -->

<property name="suppressAllComments" value="true" />

</commentGenerator>

<!-- 数据库连接信息 -->

<jdbcConnection driverClass="oracle.jdbc.OracleDriver"

connectionURL="jdbc:oracle:thin:@127.0.0.1:1521:Test"

userId="admin" password="admin" />

<javaTypeResolver>

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

</javaTypeResolver>

<!-- Model文件保存位置 -->

<javaModelGenerator targetPackage="com.metarnet.Test.DAO.Model" targetProject="Test/Model">

<!-- 开启子包 -->

<property name="enableSubPackages" value="true" />

<property name="trimStrings" value="true" />

</javaModelGenerator>

<!-- 生成的mapper文件 -->

<sqlMapGenerator targetPackage="com.metarnet.Test.DAO.XML" targetProject="Test/XML">

<property name="enableSubPackages" value="true" />

</sqlMapGenerator>

<!-- 生成的查询条件的类 -->

<javaClientGenerator targetPackage="com.metarnet.Test.DAO.Mapper" targetProject="Test/mapper" type="XMLMAPPER">

<property name="enableSubPackages" value="true" />

</javaClientGenerator>

<!-- 需要连接的表 (不生成Example(帮助类)类)-->

<table tableName="Test"

enableCountByExample="false"

enableUpdateByExample="false"

enableDeleteByExample="false"

enableSelectByExample="false"

selectByExampleQueryId="false" />

</context>

</generatorConfiguration>

-----------------------------------程序员 闫帆原创---------------------------------------

转载请注明原创人信息 程序员 闫帆yanfanvip
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐