总结一下java如何进行逆向工程

第一步在百度搜索Mybatis generator 在官网进行搜索 http://www.mybatis.org/generator/ 并且找到

 

 

 第二步导入jar包点击See the XML Configuration File Reference page for an example of a configuration file.建立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>
<!-- jar包位置 -->
  <classPathEntry location="D:\\jar\\mybatis-generator-core-1.3.5.jar" />
  
<!--  数据源信息-->
  <context id="DB2Tables" targetRuntime="MyBatis3">
  <!--禁止所有注释  -->
  <commentGenerator>
  <property name="suppressAllComments" value="true" />
</commentGenerator> 

    <jdbcConnection driverClass="com.mysql.jdbc.Driver"
        connectionURL="jdbc:mysql://localhost:3306/mybatis"
        userId="root"
        password="root">
    </jdbcConnection>

    <javaTypeResolver >
      <property name="forceBigDecimals" value="false" />
    </javaTypeResolver>
<!-- 生产实体类的位置 -->
    <javaModelGenerator targetPackage="com.zhiyou100.xth.bean" targetProject="./src">
      <property name="enableSubPackages" value="true" />
      <property name="trimStrings" value="true" />
    </javaModelGenerator>
<!-- 生产映射文件所在位置 -->
    <sqlMapGenerator targetPackage="com.zhiyou100.xth.mapper"  targetProject="./resources">
      <property name="enableSubPackages" value="true" />
    </sqlMapGenerator>
<!-- 生产dao文件的所在位置 -->
    <javaClientGenerator type="XMLMAPPER" targetPackage="com.zhiyou100.xth.dao"  targetProject="./src">
      <property name="enableSubPackages" value="true" />
    </javaClientGenerator>
   <!--表  
  schema 该表所在的数据库
  domainObjectName 实体类名
   -->
    <table schema="mybatis" tableName="users" domainObjectName="Users"
    enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample="false" enableUpdateByExample="false" 
    >
      <property name="useActualColumnNames" value="true"/>
      <generatedKey column="ID" sqlStatement="DB2" identity="true" />
      <columnOverride column="DATE_FIELD" property="startDate" />
      <ignoreColumn column="FRED" />
      <columnOverride column="LONG_VARCHAR_FIELD" jdbcType="VARCHAR" />
    </table>

  </context>
</generatorConfiguration>

 

 

第三步运行

第四步

 点击

 

第五步 

 List<String> warnings = new ArrayList<String>();
   boolean overwrite = true;
   File configFile = new File("generatorConfig.xml");
   ConfigurationParser cp = new ConfigurationParser(warnings);
   Configuration config = cp.parseConfiguration(configFile);
   DefaultShellCallback callback = new DefaultShellCallback(overwrite);
   MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
   myBatisGenerator.generate(null);

在主函数里面导包运行

 

 

       

posted @ 2019-08-30 23:00  青灯归客  阅读(3459)  评论(0编辑  收藏  举报