CustomerFormBean

用于条件查询数据库。



import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class CustomerQueryFormBean {
	private String name;
	private String cellphone;
	private String qq;
	private Date startDate;
	private Date endDate;
	private String infoSource;
	
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getCellphone() {
		return cellphone;
	}
	public void setCellphone(String cellphone) {
		this.cellphone = cellphone;
	}
	public String getQq() {
		return qq;
	}
	public void setQq(String qq) {
		this.qq = qq;
	}
	public Date getStartDate() {
		return startDate;
	}
	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}
	public Date getEndDate() {
		
		return endDate;
	}
	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}
	public String getInfoSource() {
		return infoSource;
	}
	public void setInfoSource(String infoSource) {
		this.infoSource = infoSource;
	}
	public WhereAndParam buildSqlWhere(){
//		String where="where 1=1";
		StringBuffer sb=new StringBuffer();
		List list=new ArrayList();
		sb.append(" where 1=1 ");
		
		if(this.name!=null&& !this.name.trim().equals("")){
			sb.append("and name like ? ");
			list.add("%"+name+"%");
		}
		if(this.cellphone!=null&& !this.cellphone.trim().equals("")){
			sb.append("and cellphone=? ");
			list.add(cellphone);
//			System.out.println(cellphone+"&&&&&&&&&&&&&&&&&&&&&&&&&");
		}
		if(this.qq!=null&& !this.qq.trim().equals("")){
			sb.append("and qq=? ");
			list.add(qq);
		}
		if(this.startDate!=null){
			sb.append("and regTime>=? ");
			list.add(startDate);
		}
		if(this.endDate!=null){
			//加上24小时
			sb.append("and regTime<=? ");
			Calendar calendar=Calendar.getInstance();
			calendar.setTime(this.endDate);
			calendar.add(Calendar.DATE, 1);
			list.add(calendar.getTime());
		}
		if(this.infoSource!=null&& !this.infoSource.equals("")){
			sb.append("and infoSource=? ");
			list.add(infoSource);
		}
		
		String where=sb.toString();
//		System.out.println(where+"\n");
		Object params[]=list.toArray();
		//使用内部类存储对象
		WhereAndParam wp=new WhereAndParam();
		wp.setParams(params);
		wp.setWhere(where);
		return wp;
		
	}
	public class WhereAndParam{
		
		private String where;
		private Object params[];
		public String getWhere() {
			return where;
		}
		public void setWhere(String where) {
			this.where = where;
		}
		public Object[] getParams() {
			return params;
		}
		public void setParams(Object[] params) {
			this.params = params;
		}
		
	}
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值