关于ibatis的联表查询的映射

权限设计中,现在有三个表,分别是role,role_operation,operation.现在要通过roleid得到该role的所有operation的集合。现在分别有role对象,里面有一个Set<Operation>的属性用来代表角色的权限集合。

现在的问题是role_operation表中有一个appType的列,同时operation的表中也有一个appType的列。我想通过查询结果与Bean的映射,将role_operation中的appType的值映射给相应的operation中的appType。

现在sql大概是这样:
<select id="selectRoleByRoleId" resultMap="RoleResult">
select r.ROLEID, r.ROLENAME, r.APPTYPE, r.ORGCODE,o.OPCODE,
o.OPDETAIL, o.PARENTCODE, ro.APPTYPE from ADMIN_ROLES r,
ADMIN_OPS o,ADMIN_ROLE_OP ro where o.OPCODE = ro.OPCODE and
r.ROLEID = ro.ROLEID and r.ROLEID= #value#
</select>
将来的sqlMap文件中不知道怎么写,下面是试验过的写法会报错,不过里面的红色字体表明我想达到的效果:
<resultMap class="com.tongcard.operation.web.model.Role"
groupBy="roleId" id="abatorgenerated_RoleResult">
<!--
WARNING - This element is automatically generated by Abator for iBATIS, do not modify.
This element was generated on Sun Apr 22 15:16:17 CST 2007.
-->
<result column="ROLEID" jdbcType="DECIMAL" property="roleId" />
<result column="ROLENAME" jdbcType="VARCHAR"
property="roleName" />
<result column="APPTYPE" jdbcType="DECIMAL" property="appType" />
<result column="ORGCODE" jdbcType="VARCHAR" property="orgCode" />
</resultMap>

<resultMap class="com.tongcard.operation.web.model.Role"
groupBy="roleId" id="RoleResult">
<result column="ROLEID" jdbcType="DECIMAL" property="roleId" />
<result column="ROLENAME" jdbcType="VARCHAR"
property="roleName" />
<result column="APPTYPE" jdbcType="DECIMAL" property="appType" />
<result column="ORGCODE" jdbcType="VARCHAR" property="orgCode" />
<result resultMap="DEVELOPER_ADMIN_ROLES.operationResult"
property="opers" />
</resultMap>

<resultMap class="com.tongcard.operation.web.model.Operation"
id="operationResult">
<result column="OPCODE" jdbcType="VARCHAR" property="opCode" />
<result column="OPDETAIL" jdbcType="VARCHAR"
property="opDetail" />
<result column="PARENTCODE" jdbcType="VARCHAR"
property="parentCode" />
<result column= "RO.APPTYPE" jdbcType="DECIMAL" property="appType" />
</resultMap>

不知道讲明白没有,谢谢大家。

你可能感兴趣的:(sql,bean,ibatis,sun)