多条件查询
public List findByPage(int offset, String model, String[] propertyName, String[] value, boolean rigor)
{
List valueList = new ArrayList();
StringBuffer baseHql = new StringBuffer();
String ralation = "like";
if (rigor)
{
ralation = "=";
}
baseHql.append("select model.riPrices from" + model + "as model\n");
List list = new ArrayList();
boolean first = true;
for (int i = 0; i < propertyName.length; i++)
{
if (value[i] != null)
{
if (first)
{
baseHql.append("where" + "model." + propertyName[i] + ralation + "?\n");
list.add(value[i]);
first = false;
}
else
{
baseHql.append(" and " + "model." + propertyName[i] + ralation + "?\n");
list.add(value[i]);
}
}
}
try
{
Session session = this.getSession();
Query query = session.createQuery(baseHql.toString());
query.setFirstResult(offset);
query.setMaxResults(PageModule.getPageSize());
List listResource = query.list();
Iterator it = listResource.iterator();
while (it.hasNext())
{
Object[] obj = (Object[]) it.next();
Float riPrices = (Float) obj[0];
ResourceItem resourceItem = new ResourceItem();
resourceItem.setRiPrices(riPrices);
valueList.add(resourceItem);
}
}
catch (Exception e)
{
log.error("分页查询所有资源出错", e);
}
return valueList;
}
上一篇: 我理解的优秀软件工程师
下一篇: js 判断是否为null(非空)