Mybitis模糊查询语句错误问题分析
- java代码为
List<Category> cs=session.selectList("listCategoryByName","新");
for(Category c3:cs){
System.out.println("新关键字查出的"+c.getName());
}
- 错误1
mybitis配置
<select id="listCategoryByName" resultType="Category">
select * from category_ t where t.name like concat('%',#{name},'%')
</select>
结果:报错ORA-00909: 参数个数无效
- 错误2
<select id="listCategoryByName" resultType="Category">
select * from category_ t where t.name like concat(concat("%",#{name}),"%")
</select>
结果,错误ORA-00904: “%”: 标识符无效
- 正确
select * from category_ t where t.name like concat(concat('%',#{name}),'%')