package com.shangyu.utils;
public class Test {
public static void main(String[] args) {
String str = "松江九亭";
StringBuffer sb = new StringBuffer();
for (int i = 0; i <str.length(); i++) {
if(sb.toString() != null && sb.toString() !=""){
sb.append(",");
}
sb.append(str.charAt(i));
}
String keyword = sb.toString().substring(1);
keyword = keyword.replaceAll(",", "%");
System.out.println(keyword);//结果:松%江%九%亭
}
}
模糊查询sql---->
select * from tb_table where address like '%"+str+"%'
只要查询关键字中包含 这四个字中任意一个 都能被查询到!
本文转自 沉淀人生 51CTO博客,原文链接:http://blog.51cto.com/825272560/1880109