【发布时间】:2011-10-27 08:21:13
【问题描述】:
我被堆叠了。我想直接使用 sql 代替 mybatis faramework。 我想选择具有填充属性映射的帐户列表。
但是让我们从头开始,第一个 Account 类
public class Account {
private int id;
...
private Map<String, String> properties;
...
//setters / getters
}
Account 的映射器接口很明显,映射文件包含选择
<select id="getAccountById" resultMap="account">
select ... from account where id = #{id}
</select>
<select id="getAccountProperties" resultType=map>
select * from properties where id=#{id}
</select>
第一个选择返回Account对象,第二个java.util.Map包含列名/值对。
我希望每个帐户对象都包含带有属性的映射,因此我遍历帐户列表并通过 id 选择其属性
for(Account account : accountList) {
int id = account.getId();
Map properites = mapper.getAccountProperties(id);
account.setProperties(properties);
}
而且基本上是可以的,但是200个账号需要2分钟左右,不能接受。
我希望将resultMap 与collection 一起使用会加快速度。但问题是如何
去做吧。 resultMap="account"应该是怎样的
<resultMap id="account" type="Account">
<id property="id" column="id">
...
<collection property="properties" javaType="map" column="id" select="getAccountProperties" />
</resultMap>
在这种情况下,选定的帐户对象不包含任何属性。 最大的问题是:如何将属性与帐户对象关联?
【问题讨论】: