【问题标题】:GORM - fetch results in List of Map form using HQLGORM - 使用 HQL 以地图列表形式获取结果
【发布时间】:2016-09-08 12:22:15
【问题描述】:

我有一个域名TestCase。我正在使用HQL 获取数据,如下所示:-

def query = """
          select 
          tc.testCaseObjective as tco,
          tc.testCaseStatus as tcs
          from TestCase tc

        """

println TestCase.executeQuery(query, [max: 2])

它给我的输出是:-

[["Test Case 01", "Pass"], ["work order", "Pass"]]

这是ListList 形式。

但实际上我希望ListMap 形式为:-

[[tco:"Test Case 01", tcs:"Pass"], [tco:"work order", tcs:"Pass"]]

谁能建议我如何做到这一点?我不想显式转换它。

【问题讨论】:

    标签: grails arraylist hashmap hql grails-orm


    【解决方案1】:

    使用HQL 中的select new map 语法获取解决方案,以获取MapList 中的结果,如下所示:-

    def query = """
              select 
              new map(tc.testCaseObjective as tco,
              tc.testCaseSummary as tcs)
              from TestCase tc
    
            """
    
    println TestCase.executeQuery(query, [max: 2])
    

    输出:-

    [[tco:"Test Case 01", tcs:"Pass"], [tco:"work order", tcs:"Pass"]]
    

    【讨论】:

      猜你喜欢
      • 2017-10-29
      • 2013-10-04
      • 1970-01-01
      • 2018-05-19
      • 1970-01-01
      • 2017-05-20
      • 2019-07-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多