1. 程式人生 > >SQL like 模糊查詢, in

SQL like 模糊查詢, in

[{"網際網路":["網路媒體","微博","墨跡天氣","河北天氣","其他"]},{"氣象部門":["災害大典","災情普查","災情直報","其他"]}]

 **.java檔案

if(StringUtil.isNotEmpty(dataSource)){
	if(dataSource.equals("網際網路")){
		sql_dataSource = " AND 資料來源 = '網際網路' ";
		if(StringUtil.isNotEmpty(infoSource)){
			//infoSource = infoSource.replaceAll(" +", ""); //去除字串空格
			if(infoSource.equals("其他")){
				//like 模糊查詢
				sql_infoSource = " AND 資訊來源  not like '網路媒體' and 資訊來源  not like '%微博%' and 資訊來源  not like '墨跡天氣' and 資訊來源  not like '河北天氣' ";
			} else{
				sql_infoSource = " AND 資訊來源   like '%"+ infoSource +"%' ";
			}
		}
	}else if(dataSource.equals("氣象部門")){
		sql_dataSource = " AND 資料來源 = '氣象部門' ";
		if(StringUtil.isNotEmpty(infoSource)){
			if(infoSource.equals("其他")){
				//in
				sql_infoSource = " AND 資訊來源  not in "+ "("+"'災害大典'"+","+"'災情直報'"+","+"'災情普查'"+") ";
			}else{
				sql_infoSource = " AND 資訊來源 = '" + infoSource +"' ";
			}
		}
	}else{
		sql_dataSource = " AND 資料來源 = '" + dataSource +"' ";
		if(StringUtil.isNotEmpty(infoSource)){		
				sql_infoSource = " AND 資訊來源 = '" + infoSource +"' ";
		}
	}
}

參考: