已經存在樹形菜單,每個菜單都有自己的ID,給一個菜單ID,返回從根菜單到給定菜單的菜單路徑。
存儲過程如下:
CREATE PROCEDURE SCOTT.CMODM_FUNPATH(IN FUNID INTEGER,
IN LINK VARCHAR(10),
OUT FUNPATH VARCHAR(200))
SPECIFIC SQL071108112056000
READS SQL DATA
NOT DETERMINISTIC
NULL CALL
LANGUAGE SQL
BEGIN
declare curName varchar(30);
declare curFunId integer;
set FUNPATH='''';
set curFunId=FUNID;
while(curFunId != 0)do
select pid,name into curFunId, curName from scott.cmodm_function where id=curFunId;
if(FUNPATH='''')then
set FUNPATH = curName;
else
set FUNPATH = curName||LINK||FUNPATH;
end if;
end while;
END
;
在iBatis中的調用:
sqlMap定義:
<parameterMap id="funPathMap" class="map">
<parameter property="FUNID" jdbcType="INTEGER" JavaType="int" mode="IN"/>
<parameter property="LINK" jdbcType="VARCHAR" JavaType="String" mode="IN"/>
<parameter property="FUNPATH" jdbcType="VARCHAR" JavaType="String" mode="OUT"/>
</parameterMap>
<procedure id="selectFunPath" parameterMap="funPathMap">{call scott.cmodm_funpath(?,?,?)}</procedure>
執行存儲過程:
SqlMapClient sqlMap = getSqlMapClIEnt();
Map map = new HashMap(3);
map.put("FUNID", new Integer(funId.trim()));
map.put("LINK", link);
map.put("FUNPATH", "");
try {
sqlMap.queryForObject("selectFunPath",
map);
return(String)map.get("FUNPATH");
} catch(SQLException ex) {
logger.error("獲取功能路徑失敗", ex);
return "未知功能路徑";
}