0

我的本地机器上有一个 mysql 数据库,我正在尝试使用 mybatis 为这个新数据库上的 24 个表生成 POJO 类。我正在使用 MyBatis 网站上的示例:http: //mybatis.github.io/generator/running/runningWithJava.html

    List<String> warnings = new ArrayList<String>();
    boolean overwrite = true;
    File configFile = new File("c:\\Users\\Ryan\\InfinityWorkspace\\Infinity\\src\\com\\ajtech\\infinity\\mybatis\\mybatisGenerator.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);

当我运行此代码时,控制台中不会发生异常,但运行此代码不会生成/生成任何内容。

我能够验证配置文件是否在我的 PC 上找到并且它正确解析它并且 mybatisGenerator.xml 文件中的 jdbc 连接我已使用我提供的用户名/密码成功地将我连接到 mysql 数据库。

任何想法为什么它不为我生成任何 XML / POJO 类?

我的 mybatisGenerator.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="infinityDBTables">
      <jdbcConnection connectionURL="jdbc:mysql://localhost:3307/infinitydb" 
        driverClass="com.mysql.jdbc.Driver"
        userId="Ryan"
        password="infinity">
      </jdbcConnection>

      <javaModelGenerator targetPackage="com.ajtech.infinity.database.dao.model" targetProject="\Infinity\src">
             <property name="trimStrings" value="true" />
    </javaModelGenerator>

    <sqlMapGenerator targetPackage="com.ajtech.infinity.database.dao" targetProject="\Infinity\src"/>

    <javaClientGenerator targetPackage="com.ajtech.infinity.database.dao.client" targetProject="\Infinity\src" type="XMLMAPPER"/>

    <table tableName="AccessLevel" schema="infinitydb"/>
    <table tableName="Brand" schema="infinitydb"/>
  </context>
</generatorConfiguration>

现在,我承认,我确实注意到,无论我在表标签中提供什么表名或模式名,它仍然什么都不做,也没有给出错误....幕后的表名可能有错误吗?

4

1 回答 1

1

我能够得到“mybatis-generator-core-1.3.2-sources.jar”。然后,在调试到 mybatis 生成器代码之后,我能够看到“\Infinity\src”的“targetProject”值没有被读取,尽管这似乎正是示例在 mybatis 页面上的显示方式: http: //mybatis.github.io/generator/configreference/xmlconfig.html

因此,当我将 targetProject 值更改为 C: 驱动器上的完整路径时,它起作用了:

targetProject="C:\Users\Ryan\InfinityWorkspace\Infinity\src\">
于 2014-10-20T21:34:35.987 回答