Hibernate模糊查询参数化的问题

xiaoxiao2022-06-12  30

其实造成这个问题的根本原因还是对hibernate的使用不太了解,改成这样就没错了:from Project o where 1=1 and o.isDeleted=? and o.prjName like ?; query.setString(i, "%"+实际查询条件+"%"); 注意参数中第一个百分号的左边与第二个百分号的右边都没有单引号,这和平时写SQL语句是不同的,要特别关注一下。另外还应该了解以下几点的区别: HQL:from Project o where 1=1 and  PRJ_NAME like '%strCond%';//这里PRJ_NAME 应该是数据库表中的实际字段名

HQL:from Project o where 1=1 and  o.PRJ_NAME like '%strCond%';//这里PRJ_NAME 应该是实体类的属性名 HQL:from Project o where 1=1  and PRJ_NAME like '?';//这里的?不视为占位参数 HQL:from Project o where 1=1  and PRJ_NAME like ?;//设置参数值时会自动在参数值两边加上单引号 相关资源:敏捷开发V1.0.pptx
转载请注明原文地址: https://www.6miu.com/read-4933131.html

最新回复(0)