DAO中使用内部继承实现通过多重属性查看页面中的列表

//根据是否首页,置顶,推荐
	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;
		}
	}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值