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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM