java 论坛的 获取全部版块信息

The_Distant_Light 发布于 2016/08/26 14:34
阅读 148
收藏 0
package com.api.article.list;


import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Map;
import java.util.TreeMap;


import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import net.sf.json.JSONObject;


import com.api.AppuseLog;
import com.api.ErrMsg;
import com.db.Jdbc;
import com.db.Page;
import com.module.SidToUid;
import com.sun.xml.internal.bind.v2.schemagen.xmlschema.List;


/**
 *  
 * 
 * @author WangXuDong E-mail: 1503631902@qq.com
 * @version 创建时间:2016-8-25 上午10:20:40    @file name Attention.java
 * @类说明 模块:获取全部版块
 * @操作的数据表 
 *         pw_threads(帖子基本信息表),pw_forums(版块日志数据),pw_memberdata(用户基本信息),pw_members
 *         (会员主信息表用户);
 */
public class ForumsReadlistall {


private HttpServletRequest request;
private HttpServletResponse response;
private String jsonString;


public ForumsReadlistall(HttpServletRequest request,
HttpServletResponse response) {
this.request = request;
this.response = response;
}


public  void process(String USERID, String ip, String UUID)
throws ServletException, IOException {
Jdbc db = new Jdbc(); // 获得数据库资源
Page page = new Page(); // 获得其他资源
SidToUid sidToUid = new SidToUid(request, response);// 调用SidToUid方法


String username = "";
String sql = "";
String name = "";// 版块名称
String subject = "";// 帖子标题
String icon = "";// 帖子图标
String tid = "";// 帖子id
String fans = "";// 粉丝数
String hits = "";// 点击数
//String sql1="";
//String fid="";

// sidToUid.process(USERID, "uid");// 执行方法,要求返回 的还是uid或者username
// uid = sidToUid.Msg(); // 得到uid数据赋值给uid


response.setContentType("text/html;charset=UTF-8");// 定义客户端响应的文本类型,与字符编码
request.setCharacterEncoding("UTF-8");// 定义客户端请求的字符编码
PrintWriter out = response.getWriter();
JSONObject json = new JSONObject();
ArrayList totallist = new ArrayList();

try {
// Map<String, String> map =new TreeMap<String, String>();



//sql1=("select name from pw_forums ");

//ResultSet rs1 = db.executeQuery(sql1);

// while(rs1.next())
// {
// fid =rs1.getString("fid");
// //name = rs1.getString("name");// 版块名字
// //map.put("id",name);
//
// }



sql = ("SELECT " + "pw_threads.tid," + "pw_threads.icon,"
+ "pw_threads.fid," + "pw_threads.hits,"
+ "pw_threads.subject," + "pw_forums.name,"
+ "pw_memberdata.fans " + "FROM " + "pw_threads,"
+ "pw_forums," + "pw_memberdata," + "pw_members "
+ "WHERE " + "pw_forums.fid=pw_threads.fid " + "AND "
+ "pw_members.uid=pw_memberdata.uid " + "AND "
+ "pw_members.username=pw_threads.author;");
ResultSet rs = db.executeQuery(sql);


 
while (rs.next()) {

ArrayList list = new ArrayList();
JSONObject jsonlist = new JSONObject();
name = rs.getString("name");// 版块名字
subject = rs.getString("subject");// 帖子标题
icon = rs.getString("icon");// 帖子图标
tid = rs.getString("tid");// 帖子id
fans = rs.getString("fans");// 粉丝数
hits = rs.getString("hits");// 点击数




json.put("forumid", tid );// 帖子id
json.put("name", subject);// 帖子标题
json.put("logo", icon);// 帖子图标
json.put("num", hits);// 点击数
json.put("attentionNum", fans);// 创建时间
list.add(json);


jsonlist.put("forumname", name);
jsonlist.put("forums",list);
totallist.add(jsonlist.toString());

}
if (rs != null)
rs.close();// 关闭指针


// if (rs1 != null)
// rs1.close();// 关闭指针


} catch (SQLException e) {
//out.print(map);
ErrMsg errinfo = new ErrMsg(request, response);
errinfo.ShowErrMsg("500", "查询异常");
out.print("-----"+sql);

if (db != null) {
db.close();
db = null;
}


if (page != null) {
page = null;
}
out.flush();
out.close();
return;// 程序关闭
}
out.print("{\"success\":true,\"resultCode\":\"1000\",\"msg\":\"全部论坛板块请求成功\",\"tagupdata\":\"123123123\",\"forumclass\":"
+ totallist.toString() + "}");
out.print("----------"+sql);
// 记录日志
String clasname = "全部版块---全部版块";
String claspath = this.getClass().getName();
AppuseLog add = new AppuseLog(request, response);
add.LogAdd(USERID, username, USERID, ip, claspath, clasname);


/*
* 关闭数据库资源
*/
if (db != null) {
db.close();
db = null;
}


if (page != null) {
page = null;
}


// page.getTimeA()


out.flush();
out.close();
}
}








以下是问题补充:

@The_Distant_Light:用json获取到全部版块,每个版块里都有相对应的帖子 (2016/08/26 14:36)
加载中
返回顶部
顶部