1

所以我需要像动态查找器这样的东西应该根据条件改变,让我用代码解释我的意思

以下代码按状态和 lastdateattended 查找所有员工

    def employee = Employee.findAllByStatusAndLastDateAttended("INA",dateObject)

现在我在 Employee LastDateAttended 和 LastDateSigned 中有两个字段,现在我希望如果一条记录没有 LastDateAttended,那么它应该由 LastDateSigned 找到,否则是 LastDateAttended,所以另一个条件就像

      def employee = Employee.findAllByStatusAndLastDateAttended("INA",dateObject)

我想加入并使用基于条件的查询,可以实现吗?,如果可能,请帮忙

4

3 回答 3

2

我认为条件查询在这里有意义,如下所示

Employee.createCriteria().list{
 and{
     eq('status','INA')
     or {
        eq('lastDateAttended',dateObject)
        eq('lastDateSigned',dateObject)
     }
  }    
}
于 2015-10-19T07:21:45.903 回答
0
Employee.list().findAll { emp-> 
     emp.status == "INA" && ( emp.lastDateAttended!=null?
         emp.lastDateAttended.equals(dateObject):emp.lastDateSigned.equals(dateObject)
       ) 
}
于 2015-10-19T07:42:27.000 回答
-1
Employee.findAllByStatusOrLastDateAttendedOrStatusAndLastDateAttended("INA",dateObject)
于 2015-10-19T07:28:55.107 回答