数据库查询中,我们是这样进行模糊匹配的:
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
ps.setString(1, userCondition.getUsername());
如果真这么写,你就等着扑街吧:Parameter index out of range (1 > number of parameters, which is 0)
这时候怎么破?
select * from user where 1=1 and username like ? limit 0,20
ps.setString(1, "%"+userCondition.getUsername()+"%");
PreparedStatement 模糊匹配 结果却:Parameter index out of range (1 > number of parameters, which is 0)
最新推荐文章于 2021-03-29 22:29:42 发布