📄 forumbo.java
字号:
package bo;
import myjdbc.DatabaseOperation;
import struts.actionform.ForumForm;
import java.util.List;
import vo.Topic;
import util.uid.UUIDGener;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import util.Util;
import java.util.Date;
import vo.Reply;
public class ForumBo {
private static ForumBo bo = null;
private static DatabaseOperation db = null;
private static int PAGESIZE = 10;
private ForumBo() {
db = DatabaseOperation.getInstance();
}
public static ForumBo getInstance() {
if (bo == null) {
return new ForumBo();
} else {
return bo;
}
}
/**
* 分页显示
* @param form ForumForm
*/
public void getForumList(ForumForm form) {
List result = db.executeSQLSeperatePage(
"select a.title,b.name,a.pubdate,a.topicid " +
"from topic as a , users as b where a.userid = b.userid order by pubdate desc", null,
this.PAGESIZE,
form.getCurrPage());
form.setPageCount(db.getTotalPage("select * from topic", null,
this.PAGESIZE));
System.out.println("asdf==> " + form.getPageCount());
// List result = db.executeSQL("select a.title,b.name,a.pubdate,a.topicid " +
// "from topic as a , users as b where a.userid = b.userid order by pubdate");
List list = new ArrayList();
for (int i = 0; i < result.size(); i++) {
Object[] obj = (Object[]) result.get(i);
TopicVO vo = new TopicVO();
vo.setTitle((String) obj[0]);
vo.setUsername((String) obj[1]);
vo.setPubDate(Util.date2String((Date) obj[2], "yyyy-MM-dd HH:mm:ss"));
vo.setTopicId((String) obj[3]);
list.add(vo);
}
form.setForumList(list);
}
public void getTopicList(ForumForm form) {
List list1 = db.executeSQL(
"select a.title,b.name,a.content,a.topicid,a.pubdate " +
"from topic as a,users as b where topicid = '" +
form.getId() + "' and a.userid = b.userid ");
List replyList = new ArrayList();
Object[] obj = (Object[]) list1.get(0);
TopicVO vo = new TopicVO();
vo.setTitle((String) obj[0]);
vo.setUsername((String) obj[1]);
vo.setContent((String) obj[2]);
vo.setTopicId((String) obj[3]);
vo.setPubDate(Util.date2String((Date) obj[4],
"yyyy-MM-dd HH:mm:ss"));
form.setTopicVO(vo);
List list2 = db.executeSQL(
"select a.title,b.name,a.content,a.replyid,a.pubdate " +
"from reply as a,users as b where a.topicid = '" +
form.getId() + "' and a.userid = b.userid order by a.pubdate desc");
for (int i = 0; i < list2.size(); i++) {
vo = new TopicVO();
obj = (Object[]) list2.get(i);
vo.setTitle((String) obj[0]);
vo.setUsername((String) obj[1]);
vo.setContent((String) obj[2]);
vo.setTopicId((String) obj[3]);
vo.setPubDate(Util.date2String((Date) obj[4],
"yyyy-MM-dd HH:mm:ss"));
replyList.add(vo);
}
if (replyList == null) {
replyList = new ArrayList();
}
System.out.println("asdadsf=====> " + replyList.size());
form.setReplyList(replyList);
}
public void addTopic(ForumForm form, HttpServletRequest request) {
String userid = (String) request.getSession().getAttribute("userid");
db.executeSQL("insert into topic values ('" + UUIDGener.getUUID() +
"'," +
"'" + Util.convertEncoding(form.getTopic().getTitle()) +
"'," +
"'" + Util.convertEncoding(form.getTopic().getContent()) +
"'," +
"getdate(),'" + userid + "')");
}
public void addReply(ForumForm form, HttpServletRequest request) {
String userid = (String) request.getSession().getAttribute("userid");
db.executeSQL("insert into reply values ('" + UUIDGener.getUUID() +
"'," +
"'" + Util.convertEncoding(form.getReply().getTitle()) +
"'," +
"'" + Util.convertEncoding(form.getReply().getContent()) +
"'," +
"getdate(),'" + form.getId() + "','" + userid + "')");
}
public void saveEditTopic(ForumForm form) {
db.executeSQL("update topic set title = '" +
Util.convertEncoding(form.getTopic().getTitle()) +
"',content ='" +
Util.convertEncoding(form.getTopic().getContent()) + "' " +
"where topicid = '" + form.getId() + "'");
}
public void saveEditReply(ForumForm form) {
List list = db.executeSQL("select topicid from reply where replyid = '" +
form.getId() + "'");
String temp = (String) ((Object[]) list.get(0))[0];
System.out.println("id===> " + temp);
db.executeSQL("update reply set title = '" +
Util.convertEncoding(form.getReply().getTitle()) +
"',content ='" +
Util.convertEncoding(form.getReply().getContent()) + "' " +
"where replyid = '" + form.getId() + "'");
form.setId(temp);
}
public void deleteTopic(ForumForm form) {
db.executeSQL("delete from reply where topicid = '" + form.getId() +
"'");
db.executeSQL("delete from topic where topicid = '" + form.getId() +
"'");
}
public void deleteReply(ForumForm form) {
List list = db.executeSQL("select topicid from reply where replyid = '" +
form.getId() + "'");
String temp = (String) ((Object[]) list.get(0))[0];
db.executeSQL("delete from reply where replyid = '" + form.getId() +
"'");
form.setId(temp);
}
public void getTopic(ForumForm form) {
System.out.println("asdf==>" + form.getId());
List list = db.executeSQL(
"select topicid,title,content from topic where topicid = '" +
form.getId() + "'");
if (list.size() != 0) {
Object[] obj = (Object[]) list.get(0);
Topic topic = new Topic();
topic.setTopicId((String) obj[0]);
topic.setTitle((String) obj[1]);
topic.setContent((String) obj[2]);
form.setTopic(topic);
}
}
public void getReply(ForumForm form) {
System.out.println("asdf==>" + form.getId());
List list = db.executeSQL(
"select replyid,title,content from reply where replyid = '" +
form.getId() + "'");
if (list.size() != 0) {
Object[] obj = (Object[]) list.get(0);
Reply reply = new Reply();
reply.setReplyId((String) obj[0]);
reply.setTitle((String) obj[1]);
reply.setContent((String) obj[2]);
form.setReply(reply);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -