用mybatis生成插件自动生成配置文件

1.在当前的maven项目的pom.xml中添加插件

<build>
<plugins>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version></plugin>
</plugins>
</build>

2.然后在classpath下添加配置文件generatorConifig

<?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="/home/mars/.m2/repository/mysql/mysql-connector-java/5.1.39/mysql-connector-java-5.1.39.jar"/>
<context id="MySQLTables" targetRuntime="MyBatis3">
<!--关闭注释 -->
<commentGenerator>
<property name="suppressDate" value="true"/>
</commentGenerator>
<!--数据库连接信息 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://127.0.0.1:3306/test_database" userId="root"
password="123456">
</jdbcConnection>
<!--生成的model 包路径 -->
<javaModelGenerator targetPackage="model" targetProject="src/main/java">
<property name="enableSubPackages" value="ture"/>
<property name="trimStrings" value="true"/>
</javaModelGenerator>
<!--生成xml mapper文件 路径 -->
<sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources">
<property name="enableSubPackages" value="ture"/>
</sqlMapGenerator>
<!-- 生成的Dao接口 的包路径 -->
<javaClientGenerator type="XMLMAPPER" targetPackage="dao" targetProject="src/main/java">
<property name="enableSubPackages" value="ture"/>
</javaClientGenerator>
<!--对应数据库表名 -->
<table tableName="aa"></table>
</context>
</generatorConfiguration>

3.使用mybatis-generator:generate命令来执行配置文件

用mybatis生成插件自动生成配置文件

在eclipse下先安装插件mybatis-generator1.3.5插件.然后配置生成文件配置文件

<?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="/home/mars/.m2/repository/mysql/mysql-connector-java/5.1.35/mysql-connector-java-5.1.35.jar"/>
<context id="MySQLTables" targetRuntime="MyBatis3">
<!--关闭注释 -->
<commentGenerator>
<property name="suppressDate" value="true"/>
</commentGenerator>
<!--数据库连接信息 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://23.83.232.178:3306/yxyun" userId="root"
password="123456">
</jdbcConnection>
<!--生成的model 包路径 -->
<javaModelGenerator targetPackage="com.yxyun.entity" targetProject="yxyun/src/main/java">
<property name="enableSubPackages" value="ture"/>
<property name="trimStrings" value="true"/>
</javaModelGenerator>
<!--生成xml mapper文件 路径 -->
<sqlMapGenerator targetPackage="mapper" targetProject="yxyun/src/main/resources">
<property name="enableSubPackages" value="ture"/>
</sqlMapGenerator>
<!-- 生成的Dao接口 的包路径 -->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.yxyun.dao" targetProject="yxyun/src/main/java">
<property name="enableSubPackages" value="ture"/>
</javaClientGenerator>
<!--对应数据库表名 -->
<table tableName="t_user"></table>
</context>
</generatorConfiguration>

然后右击配置文件,点击用mybatis生成插件自动生成配置文件

上一篇:Entity Framework 5中遇到的 mysql tinyint(1) 转换为 bool 的问题 (我用的是VS2013中的EF5版本)


下一篇:linux 添加基于weblogic的nodemanager的服务