This afternoon to do a function, to use the fuzzy query, the field is description, just at the beginning of my writing with the SQL in the Fuzzy query statement,
But this has a problem, only the entire value of the field is passed in to query, so it is not confused query.
Later through the search, found to add a concat field, the string must be spliced before the fuzzy query can be implemented.
After changing to this appearance, the Fuzzy query function realizes.
In the blog I searched for some other ways of writing, but tested two, one success, another failed to achieve fuzzy query, but currently do not know where the error. If anyone knows, please enlighten me.
His blog address is: http://blog.sina.com.cn/s/blog_667bef380101f2da.html
I used the first method he said:
1. String concatenation in SQL
SELECT * from TableName where name is like CONCAT (CONCAT ('% ', #{text}), '% ');
That's exactly what I did in this way.
In fact, there is a way: write like this is OK:
His second method:
2. Use ${...} instead of #{...}
SELECT * from TableName WHERE name is like '%${text}% ';
After I tried, I found that I did not realize the function of fuzzy query, and I do not know where the error is, if anyone knows please advise.
His third method:
3. Splicing in the program
Java
String searchtext = "%" + text + "%";
String SearchText = new StringBuilder ("%"). Append (Text). Append ("%"). ToString ();
Parametermap.put ("text", SearchText);
Sqlmap.xml
SELECT * from TableName WHERE name is like #{text};
I haven't tried this method, but I'll record it and try it later.
He's got a fourth way.
4. Case matching Query
SELECT * from TABLENAME WHERE UPPER (SUBSYSTEM) like '% ' | | UPPER (' JZ ') | | ‘%‘
Or
SELECT * from TABLENAME WHERE LOWER (SUBSYSTEM) like '% ' | | LOWER (' JZ ') | | ‘%‘
That's right.
Http://www.cnblogs.com/dushan/p/4766954.html
MyBatis fuzzy Query sql