数据库查询中,咱们是这样进行模糊匹配的: java
select * from user where 1=1 and username like '%林%' limit 0,20理所固然的,在java代码中你会这么写: 数据库
select * from user where 1=1 and username like '%?%' limit 0,20 get
ps.setString(1, userCondition.getUsername());若是真这么写,你就等着扑街吧:Parameter index out of range (1 > number of parameters, which is 0) it
这时候怎么破? io
select * from user where 1=1 and username like ? limit 0,20 select
ps.setString(1, "%"+userCondition.getUsername()+"%");