gpt4 book ai didi

grails - Grails中的条件动态查找器

转载 作者:行者123 更新时间:2023-12-02 14:41:30 24 4
gpt4 key购买 nike

所以我需要像动态取景器那样根据条件改变的东西,让我通过代码解释我的意思

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

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

现在我在Employee LastDateAttended和LastDateSigned中有两个字段,现在我希望如果记录中没有LastDateAttended,那么它应该由LastDateSigned查找,否则应该由LastDateAttended查找,所以另一个条件是
      def employee = Employee.findAllByStatusAndLastDateAttended("INA",dateObject)

我以某种方式希望加入并使用基于条件的两个查询,可以实现吗?如果可能,请帮助

最佳答案

Employee.list().findAll { emp-> 
emp.status == "INA" && ( emp.lastDateAttended!=null?
emp.lastDateAttended.equals(dateObject):emp.lastDateSigned.equals(dateObject)
)
}

关于grails - Grails中的条件动态查找器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33207858/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com