作业帮 > 综合 > 作业

java报错beyond number of declared ordinal parameters. Remember

来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/11/11 14:18:08
java报错beyond number of declared ordinal parameters. Remember that ordinal parameters are 1-based!
问题就出在这里
public Result getAdminRecordList(VOFilter filter) {
Result r = new Result();
Page page = filter.getPage();
EntityManager em = getEntityManager();
try {
Query query = em
.createQuery(" select count(o) from log_login as o");
Long count = (Long) query.getSingleResult();
page.setCount(count);
String jsql = " from log_login as o";
if (!StringUtil.isEmpty(filter.getKeyWord())) {
jsql += " where o.name like ? ";
}
if (filter.getOrders().size() > 0) {
jsql += " order by ";
for (Order order : filter.getOrders()) {
if ("id".equals(order.getField())) {
jsql += "o.id";
} else if ("logtime".equals(order.getField())) {
jsql += "o.logtime";
} else if ("name".equals(order.getField())) {
jsql += "o.name";
} else if ("result".equals(order.getField())) {
jsql += "o.result";
} else if ("ip".equals(order.getField())) {
jsql += "o.ip";
} else {
jsql +="o.ip";
}
if (order.getDirection() == Order.DESC) {
jsql += " desc,";
} else {
jsql += " asc ,";
}
}
jsql = jsql.substring(0, jsql.length() - 1);
}
query = em.createQuery(jsql);
query.setFirstResult(page.getStartRowNum());
query.setMaxResults(page.getPageSize());
if (!StringUtil.isEmpty(filter.getKeyWord())) {
query.setParameter(1, "%" + filter.getKeyWord() + "%");
query.setParameter(2, "%" + filter.getKeyWord() + "%");
}
r.setData(query.getResultList());
r.setPage(page);
return r;
} finally {
if (em != null) {
em.close();
}
}
}
java报错beyond number of declared ordinal parameters. Remember
hql多了参数了,你就一个占位符 - ,却使用了query.setParameter(2,"%" + filter.getKeyWord() + "%");
再问: 谢谢。。昨天就解决了。。。忘了来看。。。删掉query.setParameter(2, "%" + filter.getKeyWord() + "%"); 就可以了