日期:2014-05-18 浏览次数:21116 次
public class Privilege implements Serializable{
private Long id;
private String name;
...
private List<Privilege> subPrivilege;
public List<Privilege> getSubPrivilege() {
return subPrivilege;
}
public void setSubPrivilege(List<Privilege> subPrivilege) {
this.subPrivilege = subPrivilege;
}
...
<resultMap type="com.pojo.Privilege" id="privilege">
<id column="PRIVILEGE_ID" property="id" />
<result column="PRIVILEGE_NAME" property="name" />
<result column="PRIVILEGE_PARENT" property="parentId" />
<result column="PRIVILEGE_URL" property="url" />
<result column="PRIVILEGE_LEVEL" property="level" />
</resultMap>
<resultMap type="com.pojo.Privilege" id="subMap" extends="privilege">
<collection property="subPrivilege" ofType="com.pojo.Privilege" column="PRIVILEGE_ID" select="getSubPriv"/>
</resultMap>
<select id="getSubPriv" parameterType="long" resultMap="privilege">
select p.* from PRIVILEGE p where p.PRIVILEGE_PARENT=#{id} order by p.PRIVILEGE_ID asc
</select>
public List<Privilege> getAllPrivilegeList() {
List<Privilege> firstLevelPrivilege = privilegeDao.getFirstPrivilegeList();
List<Privilege> allPrivList = new ArrayList<Privilege>();
if(firstLevelPrivilege != null && firstLevelPriv.size() != 0){
this.mergeSubPrivilege(allPrivList,firstLevelPriv);
}
return allPrivList;
}
private void mergeSubPrivilege(List<Privilege> allPrivList, List<Privilege> currPrivList) {
for (Privilege sub_priv : currPrivList) {
allPrivList.add(sub_priv);
if (sub_priv.getSubPrivilege() != null && sub_priv.getSubPrivilege().size() != 0) {
mergeSubPrivilege(allPrivList, sub_priv.getSubPrivilege());
}
}
}