欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

多条件查询2

程序员文章站 2022-03-08 09:59:56
...

protected String generateBaseHql(String model, String[] propertyName, String[] value, String[] propertyLikeName,
String[] likeValue,List addedValues)
{

StringBuffer baseHql = new StringBuffer();

baseHql.append("from" + model + "as model  where 1=1 ");

/**
 * 处理常规值
 */
for (int i = 0; i < propertyName.length; i++)
{
if (!Converter.isEmptyString(value[i]))
{
baseHql.append("and " + "model." + propertyName[i] + "=?");
addedValues.add(value[i]);
}
}
/**
 * 处理模糊匹配
 */
for (int i = 0; i < propertyLikeName.length; i++)
{
if (!Converter.isEmptyString(likeValue[i]))
{
baseHql.append("and " + "model." + propertyLikeName[i] + "like ?");
addedValues.add(likeValue[i]);
}
}

return baseHql.toString();

}