首页 > 代码库 > ibatis的result标签中用select详解

ibatis的result标签中用select详解

标签:详解 ibatis的result标签中用select
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://zorro.blog.51cto.com/2139862/821777
 
<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

ibatis的result标签中用select详解