【Java开源代码栏目提醒】:本文主要为网学会员提供TopicAdapter.java,希望对需要TopicAdapter.java网友有所帮助,学习一下!
package
bbsmodel;
import java.util.Date;
import java.util.List;
import java.util.ListIterator;
public class TopicAdapter {
TopicCommon comm=null;
String hql="";
Topic top;
public TopicAdapter(){
comm=new TopicCommon();
top= new Topic();
}
/**
* 查询分页记录
*/
public List TopicList(int pageNum,int pageSize,int bdid) {
comm.open();
hql="from Topic where tpboardid="+bdid+"order by tptime";
//return comm.query(hql);
return comm.GetList(hql, pageNum, pageSize);
}
/**
*
查询所有记录
* @param bdid
* @return
*/
public List TopicList(int bdid) {
comm.open();
hql="from Topic where tpboardid="+bdid+"order by tptime";
return comm.query(hql);
}
public Topic OneTopic(int topicid) {
comm.open();
hql="from Topic where tpid="+topicid;
List it =comm.query(hql);
Topic topp=null;
for (ListIterator iterator = it.listIterator();
iterator.hasNext();) {
topp= (Topic) iterator.next();
}
return topp;
}
/**
* 添加新帖
* @param tptitle
* @param tpuserid
* @param tpcontent
* @param tptime
* @param tpboardid
* @return
*/
public boolean addTopic(String tptitle,int tpuserid,
String tpcontent,Date tptime,int tpboardid,String tpico) {
top.setTptitle(tptitle);
top.setTpuserid(tpuserid);
top.setTpcontent(tpcontent);
top.setTptime(tptime);
top.setTpboardid(tpboardid);
top.setTpreplynum(0);
top.setTpstop("");
top.setTpico(tpico);
comm.open();
comm.insert(top);
return true;
}
public boolean updateTopic(Topic top){
comm.open();
comm.update(top);
return true;
}
public String idtouser(int userid) {
comm.open();
hql="select username from User where userid="+userid;
List it=comm.query(hql);
return it.get(0).toString();
}
public String bdidtobdname(int bdid) {
comm.open();
hql="select bdname from Board where bdid="+bdid;
List it=comm.query(hql);
return it.get(0).toString();
}
public String idtotitle(int tpid){
comm.open();
hql="select tptitle from Topic where tpid="+tpid;
List it=comm.query(hql);
return it.get(0).toString();
}
/**
*
* @param args
*/
public static void main(String[] args) {
TopicAdapter tp=new TopicAdapter();
//tp.addTopic("视频1",2,"test",new Date(),0);
System.err.println(tp.idtouser(1));
List it =tp.TopicList(0,3,1);
for (ListIterator iterator = it.listIterator();
iterator.hasNext();) {
Topic mess = (Topic) iterator.next();
System.err.println(mess.getTpid()+"\n标题:"+
mess.getTptitle()+"\n内容:"+mess.getTpcontent()+"\n用户编号:"+
mess.getTpuserid()+"\n时间:"+mess.getTptime()+"\n版块编号:"+
mess.getTpboardid()+"\n回复数:"+mess.getTpreplynum()+"\n"
);
}
}
}