对不同的列名重复使用 resultMap

发布于 2024-07-07 12:06:40 字数 557 浏览 6 评论 0原文

有没有办法在单个查询中多次重用相同的 resultMap 。

例如,假设我有一个“foo”resultMap:

<resultMap id="foo" class="Foo">
  <result property="Bar" column="bar" />
</resultMap>

有没有办法定义另一个resultMap,为不同的列重用上述内容? 就像是...

<resultMap id="fizz"class="Fizz">
  <result property="Foo1" column="bar=bar1" resultMapping="foo" />
  <result property="Foo2" column="bar=bar2" resultMapping="foo" />
  <result property="Foo3" column="bar=bar3" resultMapping="foo" />
</resultMap>

Is there a way of reusing the same resultMap multiple times in a single query.

For example, suppose I have a "foo" resultMap:

<resultMap id="foo" class="Foo">
  <result property="Bar" column="bar" />
</resultMap>

Is there a way to define another resultMap that reuses the above for different columns? Something like...

<resultMap id="fizz"class="Fizz">
  <result property="Foo1" column="bar=bar1" resultMapping="foo" />
  <result property="Foo2" column="bar=bar2" resultMapping="foo" />
  <result property="Foo3" column="bar=bar3" resultMapping="foo" />
</resultMap>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

黎歌 2024-07-14 12:06:40

几乎。 如果您在查询中选择 Foo 的 ID,则可以让 Fizz 结果映射针对该 ID 执行 SELECT,这将使用 Foo 结果映射。

(假设您定义了 selectFoo 查询。)但这非常慢大型结果集,因为它对每一行执行额外的 SELECT。

iBATIS 针对典型情况提供了解决此问题的方法,在这种情况下,您有一个包含各种其他对象的复合对象。 首先,定义一个连接表的查询,然后可以使用 fooMap 填充 Foo

但是您不能对两个不同的 Foos 使用该结果映射两次,因为结果映射指定了某些列名称。 不过,您可以使用另一种技术:


更多详细信息请参见 iBatis Datamapper 手册第 35 页。

Almost. If you select the ID of the Foo in your query, you can have the Fizz result map execute a SELECT for that ID, which will use the Foo result map.

<result property="Foo1" column="bar1Id" select="selectFoo"/>

(Assuming you have a selectFoo query defined.) But that's extremely slow with large result sets, since it does an additional SELECT for every row.

iBATIS has a solution to this problem for the typical case, where you have a composite object that contains various other objects. First, you define a query that joins your tables, then you can use fooMap to populate a Foo:

<result property="Foo1" resultMap="fooMap"/>

But you can't use that result map twice for two different Foos because the result map specifies certain column names. You can use another technique, though:

<result property="foo1.bar" column="foo1bar"/>
<result property="foo2.bar" column="foo2bar"/>

More detail in page 35 of the iBatis Datamapper manual.

青丝拂面 2024-07-14 12:06:40

您可以使用结果映射,它扩展另一个结果映射
例如

<resultMap id="document" class="Document"> 
  <result property="Id" column="Document_ID"/>
  <result property="Title" column="Document_Title"/>
  <discriminator column="Document_Type" type="string"/>
  <subMap value="Book" resultMapping="book"/>
  <subMap value="Newspaper" resultMapping="newspaper"/>
</resultMap>

<resultMap id="book" class="Book" extends="document"> 
  <property="PageNumber" column="Document_PageNumber"/>
</resultMap>

更多信息: http://ibatis.apache.org/docs/dotnet/datamapper /ch03s05.html

you could use resultmaps, which extend another resultmap
e.g.

<resultMap id="document" class="Document"> 
  <result property="Id" column="Document_ID"/>
  <result property="Title" column="Document_Title"/>
  <discriminator column="Document_Type" type="string"/>
  <subMap value="Book" resultMapping="book"/>
  <subMap value="Newspaper" resultMapping="newspaper"/>
</resultMap>

<resultMap id="book" class="Book" extends="document"> 
  <property="PageNumber" column="Document_PageNumber"/>
</resultMap>

more info: http://ibatis.apache.org/docs/dotnet/datamapper/ch03s05.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文