标签:enc dbcc obj dem domain 错误提示 tostring 指定 ring
使用org.mybatis.generator反向生成mapper、mapper.xml、do、doExample文件,配置文件generatorConfig.xml报如下错误:The content of element type must match "property*, plugin*, commentGenerator?, jdbcConnection, javaTypeResolver?,javaModelGenerator, sqlMapGenerator?, javaClientGenerator?, table+"
配置文件 generatorConfig.xml 里面的context的子元素必须按照它给出的顺序,如错误提示的match“……”部分。
按照提示依照"property, plugin, commentGenerator?, jdbcConnection, javaTypeResolver?,javaModelGenerator, sqlMapGenerator?, javaClientGenerator?, table+"元素顺序进行配置
generatorConfig.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">
<!-- Mapper生成器配置 -->
<generatorConfiguration>
<properties resource="mybatisGenerator/generator.properties"/>
<context id="MySqlContext" targetRuntime="MyBatis3" defaultModelType="flat">
<property name="beginningDelimiter" value="`"/>
<property name="endingDelimiter" value="`"/>
<property name="javaFileEncoding" value="UTF-8"/>
<!-- 为模型生成序列化方法-->
<plugin type="org.mybatis.generator.plugins.SerializablePlugin"/>
<!-- 为生成的Java模型创建一个toString方法 -->
<plugin type="org.mybatis.generator.plugins.ToStringPlugin"/>
<commentGenerator>
<!--suppressDate是去掉生成日期那行注释-->
<property name="suppressDate" value="true"/>
<!--suppressAllComments是去掉所有的注解-->
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<!--配置数据库连接-->
<jdbcConnection driverClass="${jdbc.driverClass}"
connectionURL="${jdbc.connectionURL}"
userId="${jdbc.userId}"
password="${jdbc.password}">
<!--解决mysql驱动升级到8.0后不生成指定数据库代码的问题-->
<property name="nullCatalogMeansCurrent" value="true"/>
</jdbcConnection>
<!--指定生成model的路径-->
<javaModelGenerator targetPackage="com.xiaohang.demo"
targetProject="demo/src/main/java"/>
<!--指定生成mapper.xml的路径-->
<sqlMapGenerator targetPackage="first" targetProject="demo/src/main/resources/mapper"/>
<!--指定生成mapper接口的的路径-->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.xiaohang.demo.first"
targetProject=demo/src/main/java"/>
<!--生成全部表tableName设为%-->
<table tableName="fp_plan_recommend" domainObjectName="FpPlanRecommendDo">
<!-- 注意表中的主键ID!!!!!! -->
<!--<generatedKey column="id" sqlStatement="MySql" identity="true"/>-->
</table>
</context>
</generatorConfiguration>
GeneratorTest 生成方法
//MBG 执行过程中的警告信息
List<String> warnings = new ArrayList<String>();
//当生成的代码重复时,覆盖原代码
boolean overwrite = true;
//读取我们的 MBG 配置文件
InputStream is = GeneratorTest.class.getResourceAsStream("/mybatisGenerator/generatorConfig.xml");
ConfigurationParser cp = new ConfigurationParser(warnings);
Configuration config = cp.parseConfiguration(is);
is.close();
DefaultShellCallback callback = new DefaultShellCallback(overwrite);
//创建 MBG
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
//执行生成代码
myBatisGenerator.generate(null);
//输出警告信息
for (String warning : warnings) {
System.out.println(warning);
}
mybatis报:The content of element type must match xx
标签:enc dbcc obj dem domain 错误提示 tostring 指定 ring
原文地址:https://blog.51cto.com/12012821/2510572