濮阳杆衣贸易有限公司

主頁(yè) > 知識(shí)庫(kù) > 實(shí)現(xiàn)論壇樹型結(jié)構(gòu)的具體算法

實(shí)現(xiàn)論壇樹型結(jié)構(gòu)的具體算法

熱門標(biāo)簽:長(zhǎng)春回?fù)芡夂粝到y(tǒng)廠家 山東智能云外呼管理系統(tǒng) 珠海銷售外呼系統(tǒng)運(yùn)營(yíng)商 電銷外呼系統(tǒng) 排行榜 地圖標(biāo)注創(chuàng)業(yè)項(xiàng)目入駐 地圖標(biāo)注制作道路 四川電信外呼系統(tǒng)靠譜嗎 廣州三五防封電銷卡 外呼系統(tǒng)啥意思

實(shí)現(xiàn)論壇樹型結(jié)構(gòu)的算法很多,具體你可以去www.chinaasp.com的全文搜索中查詢。我現(xiàn)在的JSP論壇采用的也是當(dāng)中的一種:不用遞歸實(shí)現(xiàn)樹型結(jié)構(gòu)的算法,現(xiàn)在我將論壇樹型結(jié)構(gòu)的具體算法和大家介紹一下,和大家一起交流。 



1。演示表的結(jié)構(gòu): 
表名:mybbslist 
字段 
數(shù)據(jù)類型 
說明 
BBSID 自動(dòng)編號(hào)  
RootID Int 根帖ID,本身為根帖則RootID = ID 
FID Int 父帖ID,上一層帖子的ID,如是根帖則FID = 0 
DEPTH Int 根帖Level=0,其他依據(jù)回復(fù)的深度遞增 
BBSSubject Char 主題 



2。創(chuàng)建表: 
create table mybbslist ( 
forumID int(20) not null, 
bbsID int auto_increment primary key, 
rootid int(20) not null, 
fid int(20) not null, 
depth int(20) not null, 
userID int(20) not null, 
bbsUser varchar(24) not null, 
bbsSubject varchar(100) not null, 
bbsContent text, 
bbsTime varchar(30), 
bbsRead int(20), 
bbsReply int(20), 
INDEX forumID (forumID)) 



3。連接MYSQL數(shù)據(jù)庫(kù)的BEAN 
package netzero; 
import java.sql.*; 
public class mydb 

String driverName = "org.gjt.mm.mysql.Driver"; 
Connection conn = null; 
Statement stmt = null; 
ResultSet rs = null; 
String connURL= "jdbc:mysql://localhost/mybbs?user=rootpassword=howuseUnicode=truecharacterEncode=8859_1"; 
//String connURL= "jdbc:mysql://localhost/netzerobbs?user=rootpassword=how"; 
public mydb() 

try 

Class.forName(driverName); 

catch (java.lang.ClassNotFoundException e) 

System.err.println("netzero(String): " + e.getMessage()); 





public ResultSet executeQuery(String sql) throws SQLException 

conn = DriverManager.getConnection(connURL); 
stmt = conn.createStatement(); 
rs = stmt.executeQuery(sql); 
return rs; 




public boolean closeConn() 

try 

if (rs!=null) rs.close(); 
if (stmt!=null) stmt.close(); 
if (conn!=null) conn.close(); 
return true; 

catch ( SQLException ex ) 

System.err.println("closeConn: " + ex.getMessage()); 
return false; 









4。顯示論壇的JSP程序 
jsp:useBean id="mybbs" scope="session" class="netzero.mydb" /> 
%@ page contentType="text/html;charset=gb2312" %> 
%@ page import="java.io.*" %> 
%@ page import="java.sql.*" %> 

int intRowCount; 
out.print("顯示論壇樹形結(jié)構(gòu)"); 
out.print("br>br>"); 
try { 
String sql="select * from mybbslist order by rootid desc,depth,fid,bbsid"; 
ResultSet rs = mybbs.executeQuery(sql); 
if (rs.next()) 

rs.last(); 
intRowCount=rs.getRow(); 
out.print("論壇樹中有"); 
out.print(intRowCount); 
out.print("個(gè)葉子節(jié)點(diǎn)"); 
rs.first(); 
int j=0; 
int Depth = 0; 
out.print("ul>"); 
while(jintRowCount) 

int rsDepth=rs.getInt("Depth"); 
if (rsDepthDepth) 

for(int i=1;iDepth+1;i=i+1) 

out.print("/ul>"); 


rsDepth=rs.getInt("Depth"); 
if (rsDepth>Depth) 

out.print("ul>"); 

out.print("li>"); 



String bbssubject=rs.getString("bbssubject"); 
out.print(bbssubject); 
out.print("/li>"); 
Depth = rs.getInt("Depth"); 
j=j+1; 
rs.next(); 

out.print("/ul>"); 

else 

out.print("數(shù)據(jù)庫(kù)中無(wú)記錄"); 

}catch (SQLException E) { 
out.println("SQLException: " + E.getMessage()); 
out.println("SQLState: " + E.getSQLState()); 
out.println("VendorError: " + E.getErrorCode()); 

%> 
% //關(guān)閉mysql連接 
try { 
if(!mybbs.closeConn()); 
} catch (Exception ex) { 
System.err.println("closeConn: " + ex.getMessage()); 

%> 




算法參考:http://www.chinaasp.com/sqlbbs/showEssence.asp?id=4783 

標(biāo)簽:保定 紹興 北海 廣元 吳忠 肇慶 玉樹 潮州

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《實(shí)現(xiàn)論壇樹型結(jié)構(gòu)的具體算法》,本文關(guān)鍵詞  實(shí)現(xiàn),論壇,樹型,結(jié)構(gòu),的,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《實(shí)現(xiàn)論壇樹型結(jié)構(gòu)的具體算法》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于實(shí)現(xiàn)論壇樹型結(jié)構(gòu)的具體算法的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    额济纳旗| 宣恩县| 商丘市| 林芝县| 云林县| 称多县| 加查县| 鄢陵县| 宝山区| 定边县| 南昌市| 乌鲁木齐县| 措勤县| 宁波市| 甘德县| 阿鲁科尔沁旗| 威信县| 抚远县| 株洲市| 北流市| 雷波县| 建水县| 舟曲县| 台东市| 高碑店市| 东港市| 乌海市| 吴忠市| 什邡市| 宜春市| 台东县| 陆丰市| 海阳市| 嘉鱼县| 图木舒克市| 天门市| 韩城市| 楚雄市| 康保县| 昔阳县| 辽宁省|