java mybatis mapper xml:元素类型“mapper”的内容必须匹配
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16068327/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
mybatis mapper xml: The content of element type "mapper" must match
提问by Verdagon
I'm having a hard time getting my simple mybatis file to work. I have this file:
我很难让我的简单 mybatis 文件工作。我有这个文件:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="truthtree.model.mysql.UserMapper">
<typeAlias alias="User" type="truthtree.model.mysql.User" />
<select id="getAllUsers" resultType="User">
select * from User
</select>
<select id="findUserByID" resultType="User">
select *
from User
where id=#{id,javaType=int}
</select>
<select id="findByNameAndPassword" resultType="User">
select *
from User
where name = #{name,javaType=String}
and password = #{password,javaType=String}
</select>
</mapper>
I get the following exception:
我收到以下异常:
Caused by: org.xml.sax.SAXParseException: The content of element type "mapper" must match "(cache-ref|cache|resultMap*|parameterMap*|sql*|insert*|update*|delete*|select*)+".
引起:org.xml.sax.SAXParseException:元素类型“mapper”的内容必须匹配“(cache-ref|cache|resultMap*|parameterMap*|sql*|insert*|update*|delete*|select*) +”。
Which is confusing because I definitely have some s in there. Any ideas what could be wrong here? Thanks!
这令人困惑,因为我肯定有一些 s 在那里。任何想法这里可能有什么问题?谢谢!
回答by jalopaba
What you have wrong here is that the typeAlias
element does not go into the mapper
file. It's not present in the mybatis-3-mapper.dtd
. The typeAlias
element has to be included in the mybatis-config
file (inside the typeAliases
element, as it is clear in the mybatis-3-config.dtd
:
你在这里的错误是该typeAlias
元素没有进入mapper
文件。它不存在于mybatis-3-mapper.dtd
. 该typeAlias
元素必须包含在mybatis-config
文件中(在typeAliases
元素内部,正如在mybatis-3-config.dtd
:
<!ELEMENT typeAliases (typeAlias*,package*)>
<!ELEMENT typeAlias EMPTY>
<!ATTLIST typeAlias
type CDATA #REQUIRED
alias CDATA #IMPLIED
>