public List<CardScheme> getCardSchemeList(String any, Integer pageNum) { String hql = "FROM CardScheme a LEFT OUTER JOIN FETCH a.cardType WHERE a.name like ? or a.cardType.name like ? "; //Query query = getSession().createQuery(hql).setString(0,"""%" + any + "%""").setString(1, """%" + any + "%""");//查不到结果 Query query = getSession().createQuery(hql).setParameter(0, any).setParameter(1, any);//等于精确查询 return this.getPageList(query, pageNum); } public List<CardScheme> getCardSchemeList(String any, Integer pageNum) { String hql = "FROM CardScheme a LEFT OUTER JOIN FETCH a.cardType WHERE a.name like ‘%?%’ or a.cardType.name like ‘%?%’ "; Query query = getSession().createQuery(hql).setParameter(0, any).setParameter(1, any);//这种方法报错 return this.getPageList(query, pageNum); } 错误内容:No positional parameters in query: FROM CardScheme a LEFT OUTER JOIN FETCH a.cardType WHERE a.name like “”%?%”” or a.cardType.name like “”%?%”” 请问该怎么解决? |
|
10分
#1 |
查询值两边加%
|
#2 |
我上边试过啦
Query query = getSession().createQuery(hql).setString(0,”””%” + any + “%”””).setString(1, “””%” + any + “%”””);//查不到结果 |
10分
#3 |
你第二种方法, like ‘%?%’ 这里面的单引号不对,是中文的了。要不你试试直接写hql语句,不要用setParameter方法试试
|
#4 |
回复3楼:
全部都是半角英文 我使用这种方法 就会报这个错
unexpected token: or near line 1, column 115 [FROM com.tandy.invoicingsystem.entities.vip.CardScheme a LEFT OUTER JOIN FETCH a.cardType WHERE a.name like “”%?””% or a.cardType.name like “”%?””% ] |
#5 |
No positional parameters in query: FROM CardScheme a LEFT OUTER JOIN FETCH a.cardType WHERE a.name like “”%?%”” or a.cardType.name like “”%?%”” |
#6 |
Query query = getSession().createQuery(hql).setString(0,”””%” + any + “%”””).setString(1, “””%” + any + “%”””);//查不到结果
多了个单引号, |