模糊查詢java
⑴ 如何在java里做 模糊查詢
可以使用正則表達式實現, 可以字元串本身的方法實現,請看示例:
importjava.util.regex.Pattern;
/**
*@authorArvin
*@time2016/11/821:38
*/
publicclassMain{
publicstaticvoidmain(String[]args){
Stringkeyword=".(你好)";
StringcontentOne="hello.(你好)asd";//LIKE匹配
StringcontentTwo="你好";//LIKE不匹配
//方法一:利用正則表達式
//構造正則表達式
Patternregex=Pattern.compile(keyword);
System.out.println(regex.matcher(contentOne).find());//true
System.out.println(regex.matcher(contentTwo).find());//false
//方法二:利用String的contain方法
System.out.println(contentOne.contains(keyword));//true
System.out.println(contentTwo.contains(keyword));//false
//方法三:利用indexOf方法,找得到說明包含
System.out.println(contentOne.indexOf(keyword)>-1);//true
System.out.println(contentTwo.indexOf(keyword)>-1);//false
}
}
⑵ java中如何模糊查找
你這個把四個字拆開單獨找不就完了= =
所謂的模糊查找最多也就像sql裡面的like
計算機本身就是精確的。你要模糊就要加入人為判斷這是毋庸置疑的。
⑶ java 中模糊查詢
可以通過拼where條件的方式模糊查詢;
String where = 「1=1」;
if(StringUtils.isBlank(custId)){
where = where+" CUSTID = '"+custID+"'";
}
if(StringUtils.isBlank(custname)){
where = where+" CUSTNAME = '"+custname+"'";
}
。。。。。。。
這只是一種模糊查詢的方法,適用於按不確定的條件進行查詢
⑷ JAVA項目/JSP頁面 中 怎樣實現模糊查詢
jsp實現模糊查詢 實際就是在後台使用 like關鍵字和 % 符號做查詢
比如查詢所有姓 王 的人.
jsp文本框輸入王 點擊查詢按鈕 把文本框的值傳入後台 在後台拼接sql語句
select * from user where name like '王%';
'王%' 代表 以'王'字開頭 後面沒有、一個或多個字元
'%王%' 標識 只要字元中 含有 王 字就可以查詢
⑸ 如何用java實現模糊查詢
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class TestDemo {
public static void main(String[] args) {
List<String> aList=new ArrayList<String>();
aList.add("abc12de34");
aList.add("abc02de02");
String regex="^[a-zA-Z]{3}02[a-zA-Z]{2}02$";
Iterator<String> it =aList.iterator();
while(it.hasNext()){
String str=it.next();
System.out.println(str+"==");
if(str.matches(regex)){
System.out.println(str);
}
}
}
}