最近公司项目涉及到了自动建表这一块,查询的时候也就只能动态生成sql使用JdbcTemplate进行查询,在模糊查询时使用.append(" like '%?%' ") 是识别不到占位符的,.append(" like '%'?'%' ")也是报错,使用.append(" like CONCAT('%',?,'%') ")则识别不到参数类型,
![](https://img-blog.csdnimg.cn/img_convert/32dcc9968069297a9682adfa45d29a81.png)
ERROR: could not determine data type of parameter $2
通过指定类型解决。
最终的解决方案是.append(" like CONCAT('%',?::varchar,'%') ")