//根据是否首页,置顶,推荐
public List<Content> select(int isHomepage,int isRecommend,int isTop){
String sql = "";
if(isHomepage!=-1&&isRecommend==-1&&isTop==-1){
//是否首页
sql = "select * from Content where isHomepage=? order by orders";
return DBUtils.queryList(sql,new MycallBack(),isHomepage);
} else if(isHomepage==-1&&isRecommend!=-1&&isTop==-1){
//是否推荐
sql = "select * from Content where isRecommend =? order by orders";
return DBUtils.queryList(sql,new MycallBack(),isRecommend);
} else if(isHomepage==-1&&isRecommend==-1&&isTop!=-1){
//是否置顶
sql = "select * from Content where isTop=? order by orders";
return DBUtils.queryList(sql,new MycallBack(),isTop);
} else if(isHomepage!=-1&&isRecommend!=-1&&isTop==-1){
//是否首页,推荐
sql = "select * from Content where isHomepage=? and isRecommend =? order by orders";
return DBUtils.queryList(sql,new MycallBack(),isHomepage,isRecommend);
} else if(isHomepage==-1&&isRecommend!=-1&&isTop!=-1){
//是否推荐,置顶
sql = "select * from Content where isRecommend =? and isTop=? order by orders";
return DBUtils.queryList(sql,new MycallBack(),isRecommend,isTop);
} else if(isHomepage!=-1&&isRecommend==-1&&isTop!=-1){
//是否首页,置顶
sql = "select * from Content where isHomepage =? and isTop=? order by orders";
return DBUtils.queryList(sql,new MycallBack(),isHomepage,isTop);
} else{
//是否首页,推荐,置顶
sql = "select * from Content where isHomepage=? and isRecommend =? and isTop=? order by orders";
return DBUtils.queryList(sql,new MycallBack(),isHomepage,isRecommend,isTop);
}
}
//简化callBack回调函数
class MycallBack extends CallBack<Content>{
@Override
public List<Content> getDatas(ResultSet rs) {
List<Content> list = new ArrayList<Content>();
try {
Content content = null;
while(rs.next()){
content = new Content();
content.setId(rs.getInt("_id"));
content.setGraph(rs.getString("graph"));
content.setTitle(rs.getString("title"));
content.setListtitle(new listTitle((rs.getInt("lid")), rs.getString("listTitles"), null));
content.setIsHomepage(rs.getInt("isHomepage"));
content.setIsRecommend(rs.getInt("isRecommend"));
content.setIsTop(rs.getInt("isTop"));
content.setDescription(rs.getString("description"));
content.setContent(rs.getString("content"));
content.setKeyTitle(rs.getString("keyTitle"));
content.setKeywordDescript(rs.getString("keywordDescript"));
content.setOrder(rs.getInt("orders"));
content.setTitle(rs.getString("title"));
content.setSubmitTime(rs.getTimestamp("submitTime"));
content.setAnthor(rs.getString("anthor"));
content.setAdmin(new Admin(rs.getInt("aid"), "", "",""));
content.setClick(rs.getInt("click"));
list.add(content);
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
try {
if(rs != null)rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
// System.out.println("list-->"+list);
return list;
}
}
DAO中使用内部继承实现通过多重属性查看页面中的列表
最新推荐文章于 2024-09-09 14:40:58 发布