我的本地计算机上有一个 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);
当我运行此代码时,控制台中没有发生任何异常,但运行此代码不会生成/产生任何内容。
我能够验证配置文件在我的电脑上找到,并且它正确解析它,并且 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>
现在,我承认,我确实注意到,无论我在表标签中提供什么表名称或模式名称,它仍然不执行任何操作,也不会给出任何错误......幕后的表名称是否可能存在错误?
最佳答案
我能够获得“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\">
关于java - MyBatisGenerator.generate(null) 不执行任何操作,没有错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26445897/