zoukankan      html  css  js  c++  java
  • 逆向工程

    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>
    <context id="testTables" targetRuntime="MyBatis3">
    <commentGenerator>
    <!-- 是否去除自动生成的注释 true:是 : false:否 -->
    <property name="suppressAllComments" value="true" />
    </commentGenerator>
    <!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->
    <jdbcConnection driverClass="com.mysql.jdbc.Driver"
    connectionURL="jdbc:mysql://localhost:3306"

    userId="root"

    password="">
    </jdbcConnection>
    <!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer,为 true时把JDBC DECIMAL 和
    NUMERIC 类型解析为java.math.BigDecimal -->
    <javaTypeResolver>
    <property name="forceBigDecimals" value="false" />
    </javaTypeResolver>

    <!-- targetProject:生成PO类的位置 -->
    <javaModelGenerator targetPackage="(生成PO类的位置)"
    targetProject=".src">
    <!-- enableSubPackages:是否让schema作为包的后缀 -->
    <property name="enableSubPackages" value="false" />
    <!-- 从数据库返回的值被清理前后的空格 -->
    <property name="trimStrings" value="true" />
    </javaModelGenerator>
    <!-- targetProject:mapper映射文件生成的位置 -->
    <sqlMapGenerator targetPackage="(mapper映射文件生成的位置) "
    targetProject=".src">
    <!-- enableSubPackages:是否让schema作为包的后缀 -->
    <property name="enableSubPackages" value="false" />
    </sqlMapGenerator>
    <!-- targetPackage:mapper接口生成的位置 -->
    <javaClientGenerator type="XMLMAPPER"
    targetPackage="(mapper接口生成的位置 )  "
    targetProject=".src">
    <!-- enableSubPackages:是否让schema作为包的后缀 -->
    <property name="enableSubPackages" value="false" />
    </javaClientGenerator>
    <!-- 指定数据库表 -->
    <table schema="" tableName="表名"></table>
    <table schema="" tableName="表名"></table>

    </context>
    </generatorConfiguration>

    Java的代码:

    public class GeneratorSqlmap {

    public void generator() throws Exception{

    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);

    }
    public static void main(String[] args) throws Exception {
    try {
    GeneratorSqlmap generatorSqlmap = new GeneratorSqlmap();
    generatorSqlmap.generator();
    } catch (Exception e) {
    e.printStackTrace();
    }

    }

    }

  • 相关阅读:
    Please provide compiled classes of your project with sonar.java.binaries property
    全链路压测
    零宽度短网址生成器
    http://www.easytest.xyz/login_action/
    进程间的五种通信方式介绍
    InteiiJ IDEA中如何制定制定哪一个配置文件
    常见的各种排序算法汇总
    编程面试之前你应该知晓的八大数据结构
    rest-assured-doc接口自动化测试,数据驱动测试平台
    Jenkins 邮件配置 || Jenkins 发送邮件失败,提示:Error sending to the following VALID addresses
  • 原文地址:https://www.cnblogs.com/sort/p/8325036.html
Copyright © 2011-2022 走看看