我想根据几个过滤器查询属性并动态构建条件
Domain Class
PatientAttr {
def name
def value
}
标准建筑规范
if(filters.size() != 0 ){
def criteria = PatientAttr.createCriteria()
def results = criteria.list{
for (item in filters){
def name = item.name
def filter = item.filter
and{
eq 'name', name
if(filter[0] == "lt")
lt ('value', filter[1] as Double)
else if(filter[0] == "gt")
gt ('value', filter[1] as Double)
else
between ('value', filter[0] as Double, filter[1] as Double)
}
}
}
我发现只有列表的最后一个“and”语句正在被评估。标准构建器是否允许您动态构建标准?
上面的代码应该等价于这个
def results = criteria.list{
and{
eq 'name', "Serum albumin (g/dL)"
gt 'value', 3.5 as Float
}
and{
eq 'name', "M-spike (g/dL)"
gt 'value', 2.3 as Float
}
}