java mysql 多条件 组合查询

mysql 多条件组合查询

注意:里面的单引号和双引号,这里的判断也可以用eques。

//基础的SQL语句
			String sql = " select * from v_userinfo  where 1=1 ";
			//拼接查询条件---------------start-------------------------------------
			//用户姓名
			String realName = puser.getRealname();
			if(realName != null && realName.length() > 0)
			{
				sql += " and realname like '%" + realName + "%' ";
			}
			//用户性别
			String sex = puser.getSex();
			if(sex != null && sex.length() > 0)
			{
				sql += " and sex= '" + sex + "' ";
			}
			//证件类型
			int certTypeId = puser.getCertTypeID();
			if(certTypeId > 0)
			{
				sql += " and cert_type= " + certTypeId ;
			}
			//证件号码
			String cert = puser.getCert();
			if(cert != null && cert.length() > 0)
			{
				sql += " and cert like '%" + cert + "%' ";
			}
			//证件类型
			int userTypeID = puser.getUserTypeID();
			if(userTypeID > 0)
			{
				sql += " and user_type= " + userTypeID ;
			}
			
			//拼接查询条件---------------end----------------------------
			
			System.out.println("查询的SQL:" + sql );
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值