數據庫查詢中,咱們是這樣進行模糊匹配的: 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()+"%");