springJdbc like fuzzy query, Spring namedParameterJdbcTemplate like query

springJdbc like fuzzy query, Spring namedParameterJdbcTemplate like query ,

SpringJdbc named parameter like fuzzy query, namedParameterJdbcTemplate like fuzzy query

 

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

©Copyright Sweet Potato Yao July 20, 2017

http://fanshuyao.iteye.com/

 

When springJdbc uses the named template class (namedParameterJdbcTemplate) to perform like fuzzy query, how to set the like parameter?

 

Method 1: Set (%) in the sql statement

select * from jo_user WHERE  1=1   AND username LIKE '%' :username '%'  
:username must have spaces around it

If there are no spaces on both sides of :username, the data cannot be queried, as follows:
select * from jo_user WHERE  1=1   AND username LIKE '%':username'%'  

Left fuzzy query
select * from jo_user WHERE  1=1   AND username LIKE '%' :username  

Right fuzzy query
select * from jo_user WHERE  1=1   AND username LIKE :username '%'

 

Method 2: Set (%) in the value of the parameter, the query sql statement is just a named parameter

如 "%" + username + "%"

sql is as follows:

select * from jo_user WHERE 1=1 AND username LIKE :username

 

Both of the above methods have been tested and can be used with confidence.

 

After testing, the following is not possible (with double vertical bars).

SELECT * FROM ARTICLE WHERE TITLE LIKE '%' || :title || '%'

 

 

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

©Copyright Sweet Potato Yao July 20, 2017

http://fanshuyao.iteye.com/

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327101487&siteId=291194637