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
<!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
相关文章推荐
- Spring3 Mybatis3 freemarker 自动生成对应表的model、mapper、service、controller并自动修改mybatis配置文件
- 使用mybatis-generator自动生成实体类,接口实现类和Mapper映射配置文件
- 使用mybatis自动生成工具,生成对应的类,配置文件,接口
- mybatis逆向工程自动生成实体类、接口以及映射Mapper.xml配置文件
- 使用Mybatis生成工具自动生成实体类和对应的mapper映射文件以及接口文件
- 使用mybatis-generator在自动生成Model类和Mapper文件
- Mybatis使用generator自动生成映射配置文件信息
- Mybatis第六篇【配置文件和映射文件再解读、占位符、主键生成与获取、Mapper代理】
- mybatis自动生成mapper.xml和接口实体类工具
- generator.xml文件自动生成mybatis的xml配置
- MyBatis Generator作为maven插件自动生成增删改查代码及配置文件例子
- Mybatis使用generator自动生成映射配置文件信息
- IDEA中使用mybatis-generator自动生成mapper和pojo文件
- 最佳MyBatis 根据表结构自动生成代码, domain, dao, mapper 文件
- myeclipse 工具解决 struts2、ibatis(mybatis) 配置文件不自动提示
- Mybatis中使用mybatis-generator结合Ant脚本快速自动生成Model、Mapper等文件 推荐
- myBatis自动生成相关代码文件配置(Maven)
- Mybatis使用generator自动生成映射配置文件信息
- MyBatis自动生成工具去掉注释的配置
- 如何利用maven配置mybatis-generator自动生成mapper.xml