Mybatis利用 generator生成类和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驱动 -->
  <classPathEntry location="F:\generator\mysql-connector-java-5.0.8-bin.jar" />
 
  <context id="DB2Tables" targetRuntime="MyBatis3">
 <!-- 去除自动生成的注释 -->
 <commentGenerator>
  <property name="suppressAllComments" value="true" />
 </commentGenerator>
     <!-- 数据库的url 用户名 密码-->
    <jdbcConnection driverClass="com.mysql.jdbc.Driver"
        connectionURL="jdbc:mysql://localhost:3306/sy"
        userId="root"
        password="root">
    </jdbcConnection>


    <javaTypeResolver >
      <property name="forceBigDecimals" value="false" />
    </javaTypeResolver>
 
 <!-- 生成模型的包名和位置:自动生成代码的位置, -->
    <javaModelGenerator targetPackage="com.sy.model" targetProject="F:\generator\scr">
      <property name="enableSubPackages" value="true" />
      <property name="trimStrings" value="true" />
    </javaModelGenerator>
   
 <!-- 自动生成映射文件的包名和位置 -->
    <sqlMapGenerator targetPackage="com.sy.mapping"  targetProject="F:\generator\scr">
      <property name="enableSubPackages" value="true" />
    </sqlMapGenerator>

 <!-- 生成Dao 的包名和位置  -->
    <javaClientGenerator type="XMLMAPPER" targetPackage="com.sy.dao"  targetProject="F:\generator\scr">
      <property name="enableSubPackages" value="true" />
    </javaClientGenerator>
 
 <!-- tableName:用于自动生成代码的数据库表;domainObjectName:对应于数据库表的javaBean类名 -->
 <!-- 要生成那些表(更改tableName和domainObjectName就可以) -->
  <table tableName="tbug" domainObjectName="Bug" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
  <table tableName="tmenu" domainObjectName="Menu" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
  <table tableName="tonline" domainObjectName="Online" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
  <table tableName="tresource" domainObjectName="Resource" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
  <table tableName="trole" domainObjectName="Role" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
  <table tableName="trole_tresource" domainObjectName="RoleResource" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
  <table tableName="tuser" domainObjectName="User" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
  <table tableName="tuser_trole" domainObjectName="UserRole" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
  </context>
 
</generatorConfiguration>

然后在同级目录按住ctrl+shift+鼠标右键  --》在此次打开cmd窗口

执行:java -jar mybatis-generator-core-1.3.2.jar -configfile generator.xml -overwrite

注意:必须是同级目录下,文件中嵌入的路径不能有中文

猜你喜欢

转载自asblog.iteye.com/blog/2028327