Skip to content

Script Examples

Adrian A edited this page Oct 27, 2023 · 2 revisions

Print domain info.

grailsApplication.domainClasses.each {
    println "There are ${it.clazz.count()} instances of $it.clazz.simpleName"
}

Access Spring bean.

import groovy.sql.Sql
def dataSource = ctx.dataSource
def sql = Sql.newInstance(dataSource)
sql.eachRow("select * from information_schema.system_tables", {
    println it.TABLE_NAME
})

Print session variables.

session.attributeNames.each { name ->
    println name.padRight(40) + session.getAttribute(name)
}

Print request attributes.

def params = ['requestURI', 'requestURL', 'forwardURI']
params.each {
    println it + "\t" + request."$it"
}

Print all config values.

config.flatten().each { name, value ->
    println name.padRight(40) + value
}

Print all config values as a tree to the console

console.dir config

Save example domain instance with Grails4

ExampleDomainClass.withTransaction {
        ExampleDomainClass example = ExampleDomainClass.get(1)
        example.active = true
        example.save(flush:true)
    }
Clone this wiki locally
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy