@Override
public List<T> findPage(int page, int length, Map<String, Object> pram) {
List<T> result = null;
try
{
//初始化hql,this.entityClazz.getSimpleName()是泛型的真实类名,在构造函数中获取
String hql = "from " + this.entityClazz.getSimpleName() + " where 1=1 and "; //注意空格
Session session = this.sesionFactory.openSession(); //获取连接
if(!pram.isEmpty()) //判断有无条件
{
Iterator<String> it = pram.keySet().iterator(); //迭代map
while(it.hasNext())
{
String key = it.next(); //获取条件map中的key,即条件字段
hql = hql + key + " like " + "'%" + pram.get(key) + "%'" + " and "; //将字段和模糊值拼接成hql
}
}
hql += " 2=2"; //在hql末尾加上 2=2,方便hql再次拼接
System.out.println(hql);
Query query = session.createQuery(hql);
query.setFirstResult((page - 1) * length); //设置分页页码
query.setMaxResults(length); //设置每页数据长度
result = query.list(); //返回结果集
} catch (RuntimeException re)
{
throw re;
}
return result;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有