<resultMap id="usermoduleprivilege"
class="com.webex.webapp.l10n.common.pojo.UserModulePrivilege">
<result property="projectId" column="projectid" nullValue="" />
<result property="userId" column="userid" nullValue="0" />
<result property="userName" column="username" nullValue="" />
<result property="firstName" column="firstname" nullValue="" />
<result property="lastName" column="lastname" nullValue="" />
<result property="modulePrivilege"
column="{userId=userid, projectId=projectid}"
select="findassignedusermoduleprivilege" />
</resultMap>
<select id="findassignedusermoduleprivilege"
resultMap="moduleprivilege" cacheModel="Project-cache">
select t.projectid,m.moduleid,m.modulename,t.status,t.privilege from
wbxl10nprojectprivilege t,wbxl10nmodule m where
t.moduleid=m.moduleid and t.userid=#userId# and
t.projectid=#projectId#
</select>
<select id="findassigneduserprivilege"
resultMap="usermoduleprivilege">
select
distinct(u.userid),p.projectid,u.username,u.firstName,u.lastName
from wbxl10nproject p ,wbxl10nprojectprivilege t,wbxl10nuser u
where t.userid=u.userid and t.projectid=p.projectid and
t.projectid=#projectId#
</select>
由此可看出,在ibatis的resultMap的result中使用“select”是一种迭代查询,也就是例子中
<result property="modulePrivilege" column="{userId=userid, projectId=projectid}" select="findassignedusermoduleprivilege" /> 将column指定的一项或多项作为参数(
userId=userid, projectId=projectid),传入并执行指定的select语句(
findassignedusermoduleprivilege),并将查询结果赋给
property="modulePrivilege"
本文出自 “左罗CTO” 博客,请务必保留此出处http://zorro.blog.51cto.com/2139862/821777