query.setParameter总是提示越界异常

zhouyouok zhouyouok 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我想在Dao里实现查询,用Map<String,Object>封装查询条件,在Dao里查询时候老是出错,求帮助

List<T> list = null;
String hql = "from "+entity.getSimpleName()+" o where 1=1";
Session session = this.getSession();
Query query = session.createQuery(hql);
int i = 0;
if(maps!=null && maps.size()>0){
for(String propertyName:maps.keySet()){
hql+=" and o."+propertyName+"=?";
Object value = maps.get(propertyName);
query.setParameter(i++,value);
}
}
query.setFirstResult((nowPage-1)*pageSize);
query.setMaxResults(pageSize);
list = query.list();
session.close();
...全文
评论 11
收藏 已收藏
分享
返回顶部
zhouyouok
Web 开发 81,108 成员 341,721 内容