【问题标题】:How to add custom property to grails Projections如何将自定义属性添加到 grails Projections
【发布时间】:2016-08-22 09:04:09
【问题描述】:

我需要在带有 grails 条件查询的列表中添加附加值

class A{
        String name
        String address
        }

        def list=A.createCriteria.list{
          projections{
           property("name","name");
           property("additionalPropertyValue;","additionalProperty");
          // this value does not exist in domain class, but I need in list
          }
        }
    Result should have additionalPropertyValue

【问题讨论】:

  • 你能解释更多吗?那是什么财产,它来自哪里?你到底想要什么?
  • 是的,我想要自定义属性和名称,并且该属性的值由其他函数返回,例如:我也需要大写的名称值,所以我想添加属性"大写",其值为 name.toUpperCase();

标签: grails hibernate-criteria


【解决方案1】:

您可以通过这种方式添加自定义属性:

def list = A.createCriteria.list{
               projections{
                   property("name","name")
               }
           }

list.each {
   it["additionalProperty"] = additionalPropertyValue
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-18
    • 2012-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-15
    • 1970-01-01
    • 2018-02-19
    相关资源
    最近更新 更多