mybatis报:The content of element type must match xx

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mybatis报:The content of element type must match xx相关的知识,希望对你有一定的参考价值。

使用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的主要内容,如果未能解决你的问题,请参考以下文章

MyBaties 错误The content of elements must consist of well-formed character data or markup.

Mybatis 异常: The content of elements must consist of well-formed character data or markup

The content of element type "resultMap" must match "(constructor?,id*,result*,associa

上传文件报错:Warning: POST Content-Length of 9443117 bytes exceeds the limit of 8388608 bytes in Unknown

Django:创建用户模型报错: (admin.E108) The value of 'list_display[4]'解决方案

The content of element type "configuration" must match "(properties?,settings?,typeAl