【问题标题】:Grails sorting ignoring case sensitiveGrails排序忽略大小写
【发布时间】:2016-02-17 20:46:16
【问题描述】:
games = Game.where {
    categories.categoryName == currentCategory
    platform.platformName == chosenPlatform
    status == "okay"
}.list(sort: 'gameTitle', order: "asc", max: max, offset: offset)

所以我在这里按游戏名称对游戏进行排序,问题是大写字母在前,所以 Delta 在 bravo 之前,应该反过来。你如何在 grails 中做到这一点?

【问题讨论】:

    标签: grails grails-orm


    【解决方案1】:

    你必须使用派生属性

    class Game {
        String title
    
       static mapping = {
           titleUpper formula: 'UPPER(title)'
       }
    }
    

    还有你的清单

    games = Game.where {
        categories.categoryName == currentCategory
        platform.platformName == chosenPlatform
        status == "okay"
    }.list(sort: 'titleUpper', order: "asc", max: max, offset: offset)
    

    【讨论】:

      【解决方案2】:

      这是纯粹的数据库 - Grails/Gorm/Hibernate 生成一个查询,将其发送到您的数据库并处理结果 - 就是这样。如果您的数据库排序区分大小写,那么您有两种选择:

      • 将列(或整个数据库,如果可能)设置为不区分大小写。
      • ORDER BY 子句中使用函数(例如UPPERLOWER)(例如ORDER BY UPPER(game_title)

      有关公式字段的更多信息,请参阅http://grails.github.io/grails-doc/latest/guide/GORM.html#5.5.2.11%20Derived%20Properties

      【讨论】:

      • 嗨,我在 grails 文档中看不到 ORDER BY,你是如何实现的?我要做吗,列表(排序:按上排序(游戏标题),顺序:“asc”,最大值:最大值,偏移量:偏移量)?
      猜你喜欢
      • 1970-01-01
      • 2017-05-30
      • 2018-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-22
      • 2011-05-13
      • 2015-10-10
      相关资源
      最近更新 更多