gpt4 book ai didi

grails - 搜索具有逗号分隔值的记录,其中包含给定列表中的任何元素

转载 作者:行者123 更新时间:2023-12-02 14:38:04 25 4
gpt4 key购买 nike

我有一个域类Schedule,其属性为'days',其中包含逗号分隔的值,例如'2,5,6,8,9'。

Class Schedule {
String days
...
}

Schedule schedule1 = new Schedule(days :'2,5,6,8,9')
schedule1.save()

Schedule schedule2 = new Schedule(days :'1,5,9,13')
schedule2.save()

我需要从给定列表中说[2,8,11]来获取有一天的时间表列表。
Output: [schedule1]
如何编写相同的条件查询或HQL。如果可以,我们可以在日期前加上',2,5,6,8,9'等逗号作为后缀。

谢谢,

最佳答案

希望您有很好的理由进行这种非规范化-否则将列表保存到子表会更好。

否则,查询将很复杂。喜欢:

  def days = [2,8,11]
// note to check for empty days
Schedule.withCriteria {
days.each { day ->
or {
like('username', "$day,%") // starts with "$day"
like('username', "%,$day,%")
like('username', "%,$day") // ends with "$day"
}
}
}

关于grails - 搜索具有逗号分隔值的记录,其中包含给定列表中的任何元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5630505/

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