0
点赞
收藏
分享

微信扫一扫

The content of element type “resultMap“ must match “(constructor?,id*,result*,association*,collectio

m逆光生长 2023-01-19 阅读 137


The content of element type “resultMap” must match “(constructor?,id*,result*,association*,collection*,discriminator?)”


此错误我们可以定位到resultMap内部的匹配列表。问题就是我们绑定的顺序有问题


以下说明及示例来源官网

你可能想把它映射到一个智能的对象模型,这个对象表示了一篇博客,它由某位作者所写,有很多的博文,每篇博文有零或多条的评论和标签。 我们先来看看下面这个完整的例子,它是一个非常复杂的结果映射(假设作者,博客,博文,评论和标签都是类型别名)。 不用紧张,我们会一步一步地来说明。虽然它看起来令人望而生畏,但其实非常简单。

<!-- 非常复杂的结果映射 -->
<resultMap id="detailedBlogResultMap" type="Blog">

<constructor>
<idArg column="blog_id" javaType="int"/>
</constructor>

<result property="title" column="blog_title"/>

<association property="author" javaType="Author">
<id property="id" column="author_id"/>
<result property="username" column="author_username"/>
<result property="password" column="author_password"/>
<result property="email" column="author_email"/>
<result property="bio" column="author_bio"/>
<result property="favouriteSection" column="author_favourite_section"/>
</association>

<collection property="posts" ofType="Post">

<id property="id" column="post_id"/>
<result property="subject" column="post_subject"/>
<association property="author" javaType="Author"/>
<collection property="comments" ofType="Comment">
<id property="id" column="comment_id"/>
</collection>
<collection property="tags" ofType="Tag" >
<id property="id" column="tag_id"/>
</collection>

<discriminator javaType="int" column="draft">
<case value="1" resultType="DraftPost"/>
</discriminator>

</collection>

</resultMap>


由该示例可得,resultMap的结果集映射必须按照一定特定顺序进行


结果映射(resultMap)顺序:

  • constructor : 用于在实例化类时,注入结果到构造方法中
  • idArg : ID 参数;标记出作为 ID 的结果可以帮助提高整体性能
  • arg : 将被注入到构造方法的一个普通结果
  • id : 一个 ID 结果;标记出作为 ID 的结果可以帮助提高整体性能
  • result : 注入到字段或 JavaBean 属性的普通结果
  • association : 一个复杂类型的关联;许多结果将包装成这种类型嵌套结果映射 – 关联可以是 resultMap 元素,或是对其它结果映射的引用
  • collection : 一个复杂类型的集合嵌套结果映射 – 集合可以是 resultMap 元素,或是对其它结果映射的引用
  • discriminator : 使用结果值来决定使用哪个 resultMap
  • case : 基于某些值的结果映射嵌套结果映射 – case 也是一个结果映射,因此具有相同的结构和元素;或者引用其它的结果映射


举报

相关推荐

0 条评论