📄 forumbookmark.java
字号:
package com.bcxy.bbs.forum;
/**
* <p>Title:</p>
* <p>Description:</p>
* <p>Copyright:</p>
* <p>Company: www.liyunet.com</p>
*
* @author lishujiang
* @version 1.0
*/
import java.util.Vector;
import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.Logger;
import com.bcxy.bbs.util.BBSConst;
import com.bcxy.bbs.util.GCookie;
import com.bcxy.bbs.util.ParamUtil;
import com.bcxy.db.JdbcWrapper;
public class ForumBookMark {
private static Logger log = Logger.getLogger(ForumBookMark.class);
public ForumBookMark() {
}
public static void addFav(HttpServletRequest request) throws Exception {
int forumID;
try {
forumID = ParamUtil.getInt(request, "forumID");
} catch (Exception e) {
throw new Exception("请指定论坛版面。");
}
int announceID;
try {
announceID = ParamUtil.getInt(request, "announceID");
} catch (Exception e) {
throw new Exception("请指定相关贴子或者是非法的贴子参数。");
}
int rootID;
try {
rootID = ParamUtil.getInt(request, "rootID");
} catch (Exception e) {
throw new Exception("请指定相关贴子或者是非法的贴子参数。");
}
//
String url = "dispbbs.jsp?forumID=" + forumID + "&rootID=" + rootID
+ "&announceID=" + announceID;
String sql = "select topic,rootid,announceid,boardid from "
+ BBSConst.TABLE_BBS1 + " where announceid=" + announceID;
//+ " and rootid=" + rootID + " and boardid=" + forumID;固顶主题不能选择
JdbcWrapper jw = new JdbcWrapper();
try {
jw.setAutoClose(false);
jw.executeQuery(sql);
if (!jw.next()) {
throw new Exception("没有相关贴子。");
}
String topic = jw.get(1);
String userName = GCookie.getCookieValue(request, "UJBBUName", "");
sql = "insert into " + BBSConst.TABLE_BOOKMARK
+ "(username,topic,url,addtime) values('" + userName
+ "','" + topic + "','" + url + "',now())";
jw.executeUpdate(sql);
} catch (Exception e) {
log.error("添加到收藏夹出错", e);
throw e;
} finally {
jw.close();
}
}
public static Vector getBookMarkList(HttpServletRequest request)
throws Exception {
String userName = GCookie.getCookieValue(request, "UJBBUName", "");
String sql = "select * from " + BBSConst.TABLE_BOOKMARK
+ " where username='" + userName + "' order by id desc";
JdbcWrapper jw = new JdbcWrapper();
Vector bookMarkList = new Vector();
try {
jw.executeQuery(sql);
while (jw.next()) {
BookMark bookMark = new BookMark();
bookMark.setID(jw.getInt(1));
bookMark.setUserName(jw.getString(2));
bookMark.setURL(jw.getString(3));
bookMark.setTopic(jw.getString(4));
bookMark.setAddTime(jw.getString(5));
bookMarkList.add(bookMark);
}
} catch (Exception e) {
log.error("取得收藏夹列表出错", e);
throw new Exception("取得收藏夹列表出错");
} finally {
jw.close();
}
return bookMarkList;
}
public static void delBookMark(HttpServletRequest request) throws Exception {
int ID;
try {
ID = ParamUtil.getInt(request, "id");
} catch (Exception e) {
throw new Exception("请指定相应的参数!");
}
String userName = GCookie.getCookieValue(request, "UJBBUName", "");
String sql = "delete from " + BBSConst.TABLE_BOOKMARK
+ " where username='" + userName + "' and id=" + ID;
JdbcWrapper jw = new JdbcWrapper();
try {
jw.executeUpdate(sql);
} catch (Exception e) {
log.error("删除收藏夹信息出错", e);
throw new Exception("删除收藏夹信息出错");
} finally {
jw.close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -