2.要运行 generator ,需要给 generator 提供一个配置文件,指定其生成的数据库的相关信息
以oracle数据库为例子的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:数据库的JDBC驱动的jar包地址 --> <classPathEntry location="E:/path/to/local/repo/com/oracle/ojdbc14/10.2.0.3.0/ojdbc14-10.2.0.3.0.jar"/> <context id="DB2Tables" targetRuntime="MyBatis3"> <!-- 是否去除自动生成的注释 true:是,false:否 --> <commentGenerator> <property name="suppressAllComments" value="true"/> </commentGenerator> <!-- 数据库连接的信息:驱动类、连接地址、用户名、密码 --> <!-- MSSQL: driverClass="com.microsoft.sqlserver.jdbc.SQLServerDriver" connectionURL="jdbc:sqlserver://localhost:3306;DatabaseName=ibatis" --> <jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver" connectionURL="jdbc:oracle:thin:@192.168.2.141:1515:apptest" userId="zj100_apptest" password="zj100"> </jdbcConnection> <!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer true,把JDBC DECIMAL 和 NUMERIC 类型解析为java.math.BigDecimal --> <javaTypeResolver> <property name="forceBigDecimals" value="false"/> </javaTypeResolver> <!---Java 实体的生成 --> <!-- targetProject:自动生成代码的位置 --> <javaModelGenerator targetPackage="cn.sh.zj100.model" targetProject="D:\workspace\mybatis-generator-core-1.3.2-bundle\mybatis-generator-core-1.3.2\lib"> <!-- enableSubPackages:是否让schema作为包的后缀 --> <property name="enableSubPackages" value="fasle"/> <!-- 从数据库返回的值被清理前后的空格 --> <property name="trimStrings" value="false"/> </javaModelGenerator> <!--sqlMapper XML文件的生成信息,包括生成路径等 --> <sqlMapGenerator targetPackage="sqlmap" targetProject="D:\workspace\mybatis-generator-core-1.3.2-bundle\mybatis-generator-core-1.3.2\lib"> <property name="enableSubPackages" value="false"/> </sqlMapGenerator> <!--应用接口的生成信息 --> <javaClientGenerator type="XMLMAPPER" targetPackage="cn.sh.zj100.dao" implementationPackage="cn.sh.zj100.dao.impl" targetProject="D:\workspace\mybatis-generator-core-1.3.2-bundle\mybatis-generator-core-1.3.2\lib"> <property name="enableSubPackages" value="false"/> <property name="methodNameCalculator" value="extended"/> </javaClientGenerator> <!-- tableName:用于自动生成代码的数据库表;domainObjectName:对应于数据库表的javaBean类名 --> <!--<table schema="APPTEST" tableName="BBS_FORUMS" enableInsert="true" enableSelectByPrimaryKey="true" enableSelectByExample="false" enableUpdateByPrimaryKey="true" enableDeleteByPrimaryKey="false" enableDeleteByExample="false" enableCountByExample="false" enableUpdateByExample="false" modelType="flat"/>--> <table schema="APPTEST" tableName="BBS_FORUMS" enableInsert="true" enableSelectByPrimaryKey="true" enableSelectByExample="false" enableUpdateByPrimaryKey="true" enableDeleteByPrimaryKey="false" enableDeleteByExample="false" enableCountByExample="false" enableUpdateByExample="false" modelType="flat"/> </context> </generatorConfiguration>
以mysql数据库为例子的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:数据库的JDBC驱动的jar包地址 --> <classPathEntry location="D:\dbjars\mysql\mysql-connector-java-5.1.10-bin.jar"/> <context id="DB2Tables" targetRuntime="MyBatis3"> <!-- 是否去除自动生成的注释 true:是,false:否 --> <commentGenerator> <property name="suppressAllComments" value="true"/> </commentGenerator> <!-- 数据库连接的信息:驱动类、连接地址、用户名、密码 --> <!-- MSSQL: driverClass="com.microsoft.sqlserver.jdbc.SQLServerDriver" connectionURL="jdbc:sqlserver://localhost:3306;DatabaseName=ibatis" --> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://127.0.0.1:3306/jchome" userId="root" password="root"> </jdbcConnection> <!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer true,把JDBC DECIMAL 和 NUMERIC 类型解析为java.math.BigDecimal --> <javaTypeResolver> <property name="forceBigDecimals" value="false"/> </javaTypeResolver> <!---Java 实体的生成 --> <!-- targetProject:自动生成代码的位置 --> <javaModelGenerator targetPackage="cn.sh.zj100.model" targetProject="D:\workspace\mybatis-generator-core-1.3.2-bundle\mybatis-generator-core-1.3.2\lib"> <!-- enableSubPackages:是否让schema作为包的后缀 --> <property name="enableSubPackages" value="fasle"/> <!-- 从数据库返回的值被清理前后的空格 --> <property name="trimStrings" value="false"/> </javaModelGenerator> <!--sqlMapper XML文件的生成信息,包括生成路径等 --> <sqlMapGenerator targetPackage="sqlmap" targetProject="D:\workspace\mybatis-generator-core-1.3.2-bundle\mybatis-generator-core-1.3.2\lib"> <property name="enableSubPackages" value="false"/> </sqlMapGenerator> <!--应用接口的生成信息 --> <javaClientGenerator type="XMLMAPPER" targetPackage="cn.sh.zj100.dao" implementationPackage="cn.sh.zj100.dao.impl" targetProject="D:\workspace\mybatis-generator-core-1.3.2-bundle\mybatis-generator-core-1.3.2\lib"> <property name="enableSubPackages" value="false"/> <property name="methodNameCalculator" value="extended"/> </javaClientGenerator> <!-- tableName:用于自动生成代码的数据库表;domainObjectName:对应于数据库表的javaBean类名 --> <table schema="jchome" tableName="jchome_ad" domainObjectName="Ad" enableInsert="true" enableSelectByPrimaryKey="true" enableSelectByExample="false" enableUpdateByPrimaryKey="false" enableDeleteByPrimaryKey="false" enableDeleteByExample="false" enableCountByExample="false" enableUpdateByExample="false" modelType="flat"> <generatedKey column="uid" sqlStatement="MySql" identity="true"/> </table> </context> </generatorConfiguration> ===================================
|
这个配置文件提供了 mybatis-generator所需要的参数信息:
* 其中classPathEntry 是引用的jdbc的类路径,这里将jdbc jar和generator的jar包放在一起了;
* commentGenerator 是用来除去时间信息的,这在配合类似subversion的代码管理工具时使用很有效,因为可以减少没有必要的注释迁入;
* jdbcConnection是指定的jdbc的连接信息;
* javaTypeResolver式类型转换的信息,这里并没有用到;
* javaModelGenerator是模型的生成信息,这里将指定这些Java model类的生成路径;
* sqlMapGenerator是mybatis 的sqlMapper XML文件的生成信息,包括生成路径等;
* javaClientGenerator是应用接口的生成信息;
* table是用户指定的被生成相关信息的表,它必须在指定的jdbc连接中已经被建立。
3.修改你的gererator.bat文件:
@echo off
echo==========mybatis开始生成代码================
java -jar mybatis-generator-core-1.3.2.jar -configfile generator.xml -overwrite
@echo==========mybatis生成代码完毕================
echo==========mybatis开始生成代码================
java -jar mybatis-generator-core-1.3.2.jar -configfile generator.xml -overwrite
@echo==========mybatis生成代码完毕================
4.执行bat文件,即生成相关的代码
相关推荐
mybatis generator 是根据已创建的数据库数据表生成相映的 entity ,dao ,daoImpl ,sqlmap。 标签:mybatis
mybatis generator eclipse插件的安装
eclipse 插件,使用MyBatis Generator 可自动生成数据库对应的bean(有中文注释),mapper.xml和mapper dao 接口文件,可直接使用查询数据库,此插件在eclipse mars.2 版本下亲测可用,
myBatisGenerator = new MyBatisGenerator(config, callback, warnings); } catch (InvalidConfigurationException e) { e.printStackTrace(); } try { myBatisGenerator.generate(null); } catch ...
1、下载mybatis生成架包工具MyBatis_Generator_1.3.1.zip,解压架包把features、plugins文件夹下的架包分别拷贝到eclipse安装目录下的features、plugins文件夹。重启eclipse就行。 解压后图片如下: Eclipse路径...
MybatisGenerator本身是没有提供查询指定字段的,例如数据库有5个字段,我想查询其中3个字段的全部记录,这是做不到的。经过研究MybatisGenerator实现原理,在保证原有功能的基础上,实现了生成查询指定字段的相关...
1、这是Eclipse MyBatis generator 1.3.7插件的核心包 2、首先到Eclipse中下载 MyBatis Generator 1.3.7插件,下载完按步骤进行安装 打开Help > Eclipse Marketplace > Search > 输入框输入 MyBatis Generator ...
mybatis generator相关资源 包含配置文件,jar包等 补充
mybatis generator Myeclipse插件 含详细说明和mysql oracle的依赖包
MyBatis Generator是一个可以用来生成Mybatis dao,entity,Mapper文件的一个工具,在项目的过程中可以省去很多重复的工作,我们只要在MyBatis Generator的配置文件中配置好要生成的表名与包名,然后运行一条命令就会...
Mybatis Generator 结合Lombok使用,不生成get,set,生成数据库注释 自定定义 MODEL 类 数据库 使用提前:项目相关的jar 都引用了, 资源最组要是要有 mybatis-generator-core jar包 下载下来, 1 如果不改直接...
MyBatis Generator自动创建代码文件和jar包,参考http://blog.csdn.net/zhshulin/article/details/23912615
自动生成映射类 Eclipse Mybatis Generator 自动生成映射类 Eclipse Mybatis Generator
eclipse mybatis generator插件
mybatisGenerator,包括自己写的bat和xml,配置xml然后运行bat即可
mybatis generator生成器
mybatis-generator版本:mybatis-generator-core-1.3.7.jar 关于逆向工程自动生成dao层代码的功能,网上很多介绍的都是mysql版本的,而且介绍的都是在开发环境idea或eclipse中怎么使用,这里整理的是PostgerSQL版本...
使用MyBatis Generator生成DAO
使用Mybatis Generator逆向工程自动生成代码及映射文件