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 =

来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/16 02:54:16
java报错beyondnumberofdeclaredordinalparameters.Rememberthatordinalparametersare1-based!问题就出在这里publicR

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 =
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 that ordinal parameters are 1-based!问题就出在这里public Result getAdminRecordList(VOFilter filter) {Result r = new Result();Page page = filter.getPage();EntityManager em =
hql多了参数了,你就一个占位符 - ,却使用了query.setParameter(2,"%" + filter.getKeyWord() + "%");