### Grails command examples Source: https://grails.apache.org/docs/4.0.12/guide/single.html Common examples of running commands with environments or creating new applications. ```bash $ grails dev run-app $ grails create-app books ``` -------------------------------- ### YAML Configuration Example Source: https://grails.apache.org/docs/4.0.12/guide/single.html Example of a YAML configuration file used for structuring the Grails user guide. Each key maps to a specific Asciidoc template, and nesting defines the hierarchy in the Table of Contents. ```yaml introduction: title: Introduction whatsNew: title: What's new in Grails 3.2? ... ``` -------------------------------- ### create-service Command Usage Examples Source: https://grails.apache.org/docs/4.0.12/ref/Command%20Line/create-service.html Examples of invoking the create-service command with and without arguments. ```bash grails create-service ``` ```bash grails create-service book ``` ```bash grails create-service org.bookstore.Book ``` -------------------------------- ### Run Application Source: https://grails.apache.org/docs/4.0.12/guide/gettingStarted.html Start the embedded server to host the application. ```text grails> run-app ``` -------------------------------- ### Example URL Mapping Script Source: https://grails.apache.org/docs/4.0.12/api/org/grails/web/mapping/DefaultUrlMappingEvaluator.html A Groovy script example demonstrating how to define URL mappings with controller, action, and constraints. ```groovy mappings { /$post/$year?/$month?/$day?" { controller = "blog" action = "show" constraints { year(matches:/\d{4}/) month(matches:/\d{2}/) } } } ``` -------------------------------- ### Generate Project Documentation Source: https://grails.apache.org/docs/4.0.12/ref/Command%20Line/docs.html Execute the `gradle docs` command to generate user guides and API documentation. This command creates HTML and PDF outputs for the user guide, and Javadoc/Groovydoc for the API. ```bash gradle docs ``` -------------------------------- ### Grails Setup Method Transaction Persistence Source: https://grails.apache.org/docs/4.0.12/guide/testing.html Illustrates how data persisted in the `setup()` method using `save(flush: true)` will persist to the database because `setup()` runs in a separate transaction that is not rolled back. ```groovy import grails.testing.mixin.integration.Integration import grails.gorm.transactions.* import spock.lang.* @Integration @Rollback class BookSpec extends Specification { void setup() { // Below line would persist and not roll back new Book(name: 'Grails in Action').save(flush: true) } void "test something"() { expect: Book.count() == 1 } } ``` -------------------------------- ### Generate-all Command Usage Examples Source: https://grails.apache.org/docs/4.0.12/ref/Command%20Line/generate-all.html Examples of invoking the generate-all command with different arguments to scaffold domain classes. ```bash grails generate-all grails generate-all org.bookstore.Book grails generate-all "*" ``` -------------------------------- ### Accept Header Examples Source: https://grails.apache.org/docs/4.0.12/guide/single.html Examples of common HTTP Accept header values sent by browsers and non-browser clients. ```text */* ``` ```text text/xml, application/xml, application/xhtml+xml, text/html;q=0.9, \ text/plain;q=0.8, image/png, */*;q=0.5 ``` ```text application/json ``` -------------------------------- ### Install Grails using SDKMAN Source: https://grails.apache.org/docs/4.0.12/guide/single.html Install the latest version of Grails using the SDKMAN package manager. ```bash sdk install grails ``` -------------------------------- ### Container Renderer Example Source: https://grails.apache.org/docs/4.0.12/guide/REST.html Example of implementing a ContainerRenderer for lists of objects, specifying target and component types, and MIME types. ```groovy class BookListRenderer implements ContainerRenderer { Class getTargetType() { List } Class getComponentType() { Book } MimeType[] getMimeTypes() { [ MimeType.XML] as MimeType[] } void render(List object, RenderContext context) { .... } } ``` -------------------------------- ### Build Grails Installation from Source Source: https://grails.apache.org/docs/4.0.12/guide/contributing.html Build a Grails installation from the cloned source code using Gradle. This command fetches dependencies and builds the necessary files. It skips extensive test class collection. ```bash ./gradlew install ``` -------------------------------- ### GET /plugin/instance Source: https://grails.apache.org/docs/4.0.12/api/index-all.html Methods for retrieving plugin instances and configuration. ```APIDOC ## GET /plugin/instance ### Description Retrieves the wrapped plugin instance and configuration details for Grails plugins. ### Methods - getInstance() - Retrieves the wrapped plugin instance. - getLoadAfterNames() - Returns names of plugins that should be loaded after this one. ### Response - **instance** (GrailsPlugin) - The plugin instance object. ``` -------------------------------- ### Grails Domain Class Example Source: https://grails.apache.org/docs/4.0.12/ref/Plug-ins/hibernate.html An example of a Grails domain class. Refer to the GORM section of the Grails user guide for more details on creating domain classes. ```groovy class Book { String title Date releaseDate Author author } ``` -------------------------------- ### Pagination and Caching with findAll Source: https://grails.apache.org/docs/4.0.12/ref/Domain%20Classes/findAll.html Examples showing how to apply pagination and enable the 2nd level cache during queries. ```Groovy Book.findAll("from Book as b where b.author=:author", [author: 'Dan Brown'], [max: 10, offset: 5]) ``` ```Groovy Book.findAll("from Book as b where b.author=:author", [author:'Dan Brown'], [max: 10, offset: 5, cache: true]) ``` -------------------------------- ### Create unit test command examples Source: https://grails.apache.org/docs/4.0.12/ref/Command%20Line/create-unit-test.html Demonstrates various ways to invoke the create-unit-test command with and without specific class names or packages. ```bash grails create-unit-test grails create-unit-test book grails create-unit-test org.bookstore.Book ``` -------------------------------- ### Clone Grails Core Repository Source: https://grails.apache.org/docs/4.0.12/guide/contributing.html Clone the Grails core framework repository from GitHub to start contributing. Ensure you have a Git client installed. ```bash git clone http://github.com/grails/grails-core.git ``` -------------------------------- ### Run create-domain-class command Source: https://grails.apache.org/docs/4.0.12/ref/Command%20Line/create-domain-class.html Examples of executing the create-domain-class command with different naming conventions. ```bash grails create-domain-class grails create-domain-class Book grails create-domain-class org.bookstore.Book ``` -------------------------------- ### Basic RestfulController Implementation Source: https://grails.apache.org/docs/4.0.12/guide/REST.html Extends the RestfulController super class to create a basic RESTful resource controller. This provides a quick way to get started with REST APIs. ```Groovy class BookController extends RestfulController { static responseFormats = ['json', 'xml'] BookController() { super(Book) } } ``` -------------------------------- ### Create Grails Criteria Query Source: https://grails.apache.org/docs/4.0.12/ref/Domain%20Classes/createCriteria.html Use `createCriteria()` to get an instance of HibernateCriteriaBuilder for constructing criteria queries. Criterion methods can be statically imported or called directly on the criteria instance. This example demonstrates filtering by name, balance, and branch, with ordering and limiting results. ```groovy def c = Account.createCriteria() def results = c.list { like("holderFirstName", "Fred%") and { between("balance", 500, 1000) eq("branch", "London") } maxResults(10) order("holderLastName", "desc") } ``` -------------------------------- ### Packaging and Running Application Source: https://grails.apache.org/docs/4.0.12/guide/conf.html Package the application into a WAR file and execute it using the java command. ```bash $ grails package $ java -jar build/libs/myapp-0.1.war ``` -------------------------------- ### Verify Grails Installation Source: https://grails.apache.org/docs/4.0.12/guide/gettingStarted.html Check if Grails is installed correctly by running the `grails -version` command in your terminal. This should display the installed Grails version. ```bash grails -version ``` -------------------------------- ### Install Grails Development Version with SDKMAN Source: https://grails.apache.org/docs/4.0.12/guide/contributing.html Use SDKMAN to install a local Grails development version from a specified path. This is useful for managing multiple Grails installations. ```bash sdk install grails dev /path/to/grails-core ``` -------------------------------- ### Initialize Grails Project Source: https://grails.apache.org/docs/4.0.12/guide/gettingStarted.html Navigate to the project directory and launch the Grails interactive console. ```bash $ cd helloworld $ grails ``` -------------------------------- ### onStartup Method Source: https://grails.apache.org/docs/4.0.12/api/org/grails/plugins/web/servlet/context/BootStrapClassRunner.html Executes the BootStrap startup logic for the Grails application. ```APIDOC ## void onStartup(Map event) ### Description Triggers the startup sequence for BootStrap classes within the Grails application. ### Parameters #### Request Body - **event** (Map) - Required - A map containing event-related data for the startup process. ``` -------------------------------- ### Trim start of string Source: https://grails.apache.org/docs/4.0.12/api/grails/util/GrailsStringUtils.html Removes the specified prefix from the start of the string. ```java static java.lang.String trimStart(java.lang.String str, java.lang.String start) ``` -------------------------------- ### Create a standard Grails application Source: https://grails.apache.org/docs/4.0.12/ref/Command%20Line/create-app.html Initializes a new application in a subdirectory named after the project. ```bash $ grails create-app bookstore $ cd bookstore ``` -------------------------------- ### Set Post-Creation Instructions Source: https://grails.apache.org/docs/4.0.12/guide/profiles.html Define text to display after application creation. ```yaml instructions: Here are some instructions ``` -------------------------------- ### JSON View Output Example Source: https://grails.apache.org/docs/4.0.12/guide/REST.html The output generated by the basic JSON view example. ```json {"person":{"name":"bob"}} ``` -------------------------------- ### generate-controller command usage examples Source: https://grails.apache.org/docs/4.0.12/ref/Command%20Line/generate-controller.html Examples of invoking the generate-controller command with different arguments. ```bash grails generate-controller grails generate-controller org.bookstore.Book grails generate-controller "*" ``` -------------------------------- ### Create Tag Library Command Examples Source: https://grails.apache.org/docs/4.0.12/ref/Command%20Line/create-taglib.html Demonstrates various ways to invoke the create-taglib command, including interactive mode, simple naming, and package-qualified naming. ```bash grails create-taglib ``` ```bash grails create-taglib book ``` ```bash grails create-taglib org.bookstore.Book ``` -------------------------------- ### Basic Script Implementation Source: https://grails.apache.org/docs/4.0.12/guide/commandLine.html A simple script example that prints output to the console. ```groovy description "Example description", "grails hello-world" println "Hello World" ``` -------------------------------- ### Define Configuration Properties Source: https://grails.apache.org/docs/4.0.12/guide/spring.html Example entries for application.groovy or externalized configuration files. ```groovy database.driver="com.mysql.jdbc.Driver" database.dbname="mysql:mydb" ``` -------------------------------- ### Criteria Method Examples Source: https://grails.apache.org/docs/4.0.12/ref/Domain%20Classes/createCriteria.html Examples of various criteria methods used to filter and order database results. ```Groovy between("balance", 500, 1000) ``` ```Groovy eq("branch", "London") ``` ```Groovy eq("branch", "london", [ignoreCase: true]) ``` ```Groovy eqProperty("lastTx", "firstTx") ``` ```Groovy gt("balance",1000) ``` ```Groovy gtProperty("balance", "overdraft") ``` ```Groovy ge("balance", 1000) ``` ```Groovy geProperty("balance", "overdraft") ``` ```Groovy idEq(1) ``` ```Groovy ilike("holderFirstName", "Steph%") ``` ```Groovy 'in'("age",[18..65]) or not {'in'("age",[18..65])} ``` ```Groovy isEmpty("transactions") ``` ```Groovy isNotEmpty("transactions") ``` ```Groovy isNull("holderGender") ``` ```Groovy isNotNull("holderGender") ``` ```Groovy lt("balance", 1000) ``` ```Groovy ltProperty("balance", "overdraft") ``` ```Groovy le("balance", 1000) ``` ```Groovy leProperty("balance", "overdraft") ``` ```Groovy like("holderFirstName", "Steph%") ``` ```Groovy ne("branch", "London") ``` ```Groovy neProperty("lastTx", "firstTx") ``` ```Groovy order("holderLastName", "desc") ``` ```Groovy rlike("holderFirstName", /Steph.+/) ``` ```Groovy sizeEq("transactions", 10) ``` ```Groovy sizeGt("transactions", 10) ``` ```Groovy sizeGe("transactions", 10) ``` ```Groovy sizeLt("transactions", 10) ``` ```Groovy sizeLe("transactions", 10) ``` ```Groovy sizeNe("transactions", 10) ``` ```Groovy sqlRestriction "char_length(first_name) = 4" ``` -------------------------------- ### Implement Show Action with Respond Source: https://grails.apache.org/docs/4.0.12/guide/REST.html A concise implementation of the 'show' action that uses 'respond' to handle domain instance lookup and rendering. ```Groovy def show(Book book) { respond book } ``` -------------------------------- ### Example XML Request Body Source: https://grails.apache.org/docs/4.0.12/guide/REST.html An example XML structure used for binding to a Book domain object. ```xml The Stand Stephen King ``` -------------------------------- ### Generate documentation Source: https://grails.apache.org/docs/4.0.12/guide/contributing.html Build the documentation using the Gradle wrapper, skipping API documentation for faster execution. ```bash $ ./gradlew publishGuide -x apiDocs ``` -------------------------------- ### Querying Domain Instances with findAll Source: https://grails.apache.org/docs/4.0.12/ref/Domain%20Classes/findAll.html Demonstrates various HQL, positional, named parameter, and query-by-example patterns for retrieving domain objects. ```Groovy // everything Book.findAll() // with a positional parameter Book.findAll("from Book as b where b.author=?", ['Dan Brown']) // 10 books from Dan Brown staring from 5th book ordered by release date Book.findAll("from Book as b where b.author=? order by b.releaseDate", ['Dan Brown'], [max: 10, offset: 5]) // examples with max/offset usage def query = "from Book as b where b.author='Dan Brown' order by b.releaseDate" // first 10 books Book.findAll(query, [max: 10]) // 10 books starting from 5th Book.findAll(query, [max: 10, offset: 5]) // examples with named parameters Book.findAll("from Book as b where b.author=:author", [author: 'Dan Brown']) Book.findAll("from Book as b where b.author=:author", [author: 'Dan Brown'], [max: 10, offset: 5]) Book.findAll("from Book as b where b.author in (:authors)", [authors: ['Dan Brown', 'Jack London']]) // examples with tables join Book.findAll("from Book as b where not exists " + "(from Borrow as br where br.book = b)") // query by example def example = new Book(author: "Dan Brown") Book.findAll(example) // Use where criteria (since Grails 2.0) def results = Person.findAll { lastName == "Simpson" } def results = Person.findAll(sort:"firstName") { lastName == "Simpson" } ``` -------------------------------- ### Install Specific Grails Version using SDKMAN Source: https://grails.apache.org/docs/4.0.12/guide/single.html Install a specific version of Grails, such as 4.0.12, using SDKMAN. ```bash sdk install grails 4.0.12 ``` -------------------------------- ### Publish profile to local repository Source: https://grails.apache.org/docs/4.0.12/guide/profiles.html After configuring your profile, use the `gradle install` command to publish it to your local repository, making it available for use. ```bash $ gradle install ``` -------------------------------- ### Vnd.Error JSON Response Example Source: https://grails.apache.org/docs/4.0.12/guide/REST.html This is an example of a Vnd.Error JSON response when the client accepts `application/vnd.error+json` and validation errors occur. ```shell $ curl -i -H "Accept: application/vnd.error+json,application/json" -H "Content-Type: application/json" -X POST -d "" http://localhost:8080/books HTTP/1.1 200 OK Server: Apache-Coyote/1.1 Content-Type: application/vnd.error+json;charset=ISO-8859-1 [ { "logref": "book.nullable, "message": "Property [title] of class [class rest.test.Book] cannot be null", "_links": { "resource": { "href": "http://localhost:8080/rest-test/books" } } } ] ``` -------------------------------- ### Using the respond method Source: https://grails.apache.org/docs/4.0.12/ref/Controllers/respond.html Demonstrates basic usage of the respond method to return content based on negotiation, including restricting output formats. ```Groovy // pick the best content type to respond with respond Book.get(1) // pick the best content type to respond with from the given formats respond Book.get(1), formats: ['xml', 'json'] ``` -------------------------------- ### Grails 3.0 Multi-Project Setup Source: https://grails.apache.org/docs/4.0.12/guide/single.html Commands and configuration for setting up inline-style plugins in Grails 3.x. ```bash $ grails create-app myapp $ grails create-plugin myplugin ``` ```gradle include 'myapp', 'myplugin' ``` ```gradle compile project(':myplugin') ``` -------------------------------- ### External Bean Definition Script Example Source: https://grails.apache.org/docs/4.0.12/guide/spring.html An example of a Groovy script file containing bean definitions to be loaded by BeanBuilder. ```groovy import org.apache.commons.dbcp.BasicDataSource import org.grails.orm.hibernate.ConfigurableLocalSessionFactoryBean beans { dataSource(BasicDataSource) { driverClassName = "org.h2.Driver" url = "jdbc:h2:mem:grailsDB" username = "sa" password = "" } sessionFactory(ConfigurableLocalSessionFactoryBean) { dataSource = dataSource hibernateProperties = ["hibernate.hbm2ddl.auto": "create-drop", "hibernate.show_sql": "true"] } } ``` -------------------------------- ### Grails Build Output Example Source: https://grails.apache.org/docs/4.0.12/guide/plugins.html This output demonstrates the Gradle build process, including the compilation and processing steps for both the plugin and the application. It confirms that plugin sources are being built and placed on the application's classpath. ```text :myplugin:compileAstJava UP-TO-DATE :myplugin:compileAstGroovy UP-TO-DATE :myplugin:processAstResources UP-TO-DATE :myplugin:astClasses UP-TO-DATE :myplugin:compileJava UP-TO-DATE :myplugin:configScript UP-TO-DATE :myplugin:compileGroovy :myplugin:copyAssets UP-TO-DATE :myplugin:copyCommands UP-TO-DATE :myplugin:copyTemplates UP-TO-DATE :myplugin:processResources :myapp:compileJava UP-TO-DATE :myapp:compileGroovy :myapp:processResources UP-TO-DATE :myapp:classes :myapp:findMainClass :myapp:bootRun Grails application running at http://localhost:8080 in environment: development ``` -------------------------------- ### Install Local Grails Plugin Source: https://grails.apache.org/docs/4.0.12/guide/plugins.html Use this command to install a Grails plugin into your local Maven cache, making it available for use in other projects. ```bash grails install ``` -------------------------------- ### List available Grails plugins Source: https://grails.apache.org/docs/4.0.12/ref/Command%20Line/list-plugins.html Executes the command to list installable plugins. Note that execution time depends on internet connectivity. ```bash grails list-plugins ``` ```bash grails list-plugins grails list-plugins -repository=myRepository ``` -------------------------------- ### Example script content Source: https://grails.apache.org/docs/4.0.12/ref/Command%20Line/create-script.html The generated Groovy script file structure for custom commands. ```groovy description "Example description", "grails example-usage" println "Example Script" ``` -------------------------------- ### Interactive Grails Application Mode Source: https://grails.apache.org/docs/4.0.12/guide/gettingStarted.html Start the application in interactive mode to quickly restart the server. Use `run-app` to start and `stop-app` to shut down. ```bash $ grails grails> run-app | Grails application running at http://localhost:8080 in environment: development grails> stop-app | Shutting down application... | Application shutdown. grails> run-app | Grails application running at http://localhost:8080 in environment: development ``` -------------------------------- ### FileSystemResource Constructors Source: https://grails.apache.org/docs/4.0.12/api/org/grails/io/support/FileSystemResource.html Details on how to instantiate a FileSystemResource. ```APIDOC ## FileSystemResource Constructors ### Constructor Summary Constructors and their descriptions: * `FileSystemResource(java.io.File file)` Create a new FileSystemResource from a File handle. * `FileSystemResource(java.lang.String path)` Create a new FileSystemResource from a file path. ### Constructor Detail * #### public **FileSystemResource**(java.io.File file) Create a new FileSystemResource from a File handle. **Parameters:** * `file` (java.io.File) - a File handle * #### public **FileSystemResource**(java.lang.String path) Create a new FileSystemResource from a file path. **Parameters:** * `path` (java.lang.String) - a file path ``` -------------------------------- ### Message Bundle Property Example Source: https://grails.apache.org/docs/4.0.12/guide/i18n.html Example of a message bundle property file entry. The key 'my.localized.content' maps to the specified localized string. ```properties my.localized.content=Hola, me llamo John. Hoy es domingo. ``` -------------------------------- ### Grails Factories File Example Source: https://grails.apache.org/docs/4.0.12/guide/plugins.html Example of a `META-INF/grails.factories` descriptor file that lists trait injectors. This file is automatically generated but can be manually defined if needed. ```properties #Grails Factories File grails.compiler.traits.TraitInjector= myplugin.ControllerTraitInjector,myplugin.DateTraitTraitInjector ``` -------------------------------- ### static void main(java.lang.String[] args) Source: https://grails.apache.org/docs/4.0.12/api/grails/ui/command/GrailsApplicationContextCommandRunner.html Main method to run an existing Application class. ```APIDOC ## static void main(java.lang.String[] args) ### Description Main method to run an existing Application class. ### Parameters #### Query Parameters - **args** (String[]) - Required - The first argument is the Command name, the last argument is the Application class name ``` -------------------------------- ### Retrieve domain instances using getAll Source: https://grails.apache.org/docs/4.0.12/ref/Domain%20Classes/getAll.html Demonstrates retrieving domain instances using variable arguments, a list of IDs, or no arguments to fetch all instances. ```groovy // get a list which contains Book instances with ids 2, 1, 3 respectively def bookList = Book.getAll(2, 1, 3) // can take a list of ids as only argument, very // useful when the ids list is calculated in code def bookList = Book.getAll([1, 2, 3]) // when called without arguments returns list of all objects def bookList = Book.getAll() ``` -------------------------------- ### Example Grails command class Source: https://grails.apache.org/docs/4.0.12/ref/Command%20Line/create-command.html This is an example of a generated Grails command class. It implements the ApplicationCommand interface and can access application beans like DataSource. ```groovy import grails.dev.commands.* class MyExampleCommand implements ApplicationCommand { boolean handle(ExecutionContext ctx) { def dataSource = applicationContext.getBean(DataSource) return true } } ``` -------------------------------- ### Publish Local Grails Installation to Maven Source: https://grails.apache.org/docs/4.0.12/guide/contributing.html Publish your local Grails development installation to your local Maven repository. This allows your local build to be used by other projects. ```bash ./gradlew pTML ``` -------------------------------- ### Configure SSL via command-line Source: https://grails.apache.org/docs/4.0.12/guide/deployment.html Use system properties to override or set SSL configuration during application startup. ```bash -Dserver.ssl.enabled=true -Dserver.ssl.key-store=/path/to/keystore ``` -------------------------------- ### Create an application with a custom profile Source: https://grails.apache.org/docs/4.0.12/guide/single.html Uses the custom profile to scaffold a new application. ```bash $ grails create-app myapp --profile mycompany ``` ```bash $ grails create-app myapp --profile com.mycompany:mycompany:1.0.1 ``` -------------------------------- ### Basic JSON View Example Source: https://grails.apache.org/docs/4.0.12/guide/REST.html Create a .gson file in grails-app/views to define a JSON structure. This example creates a simple JSON object with a 'name' property. ```groovy json.person { name "bob" } ``` -------------------------------- ### Create Controller and Unit Test Source: https://grails.apache.org/docs/4.0.12/guide/testing.html Use the `create-controller` command to generate a controller and its corresponding unit test file. ```bash grails create-controller com.acme.app.simple ``` -------------------------------- ### Install Grails with SDKMAN Source: https://grails.apache.org/docs/4.0.12/guide/gettingStarted.html Use SDKMAN to install the latest version of Grails or a specific version like 4.0.12. SDKMAN simplifies managing multiple Grails versions. ```bash sdk install grails ``` ```bash sdk install grails 4.0.12 ``` -------------------------------- ### Rendered Scaffolding Tag Example Source: https://grails.apache.org/docs/4.0.12/ref/Constraints/attributes.html Illustrates how custom attributes are rendered in a GSP tag for scaffolding. The example shows a `g:datePicker` tag with a limited year range. ```HTML ``` -------------------------------- ### Groovy Configuration Example Source: https://grails.apache.org/docs/4.0.12/guide/conf.html Example of using Groovy's ConfigSlurper syntax for Grails configuration. The `userHome`, `grailsHome`, `appName`, and `appVersion` variables are available within the configuration script. ```groovy my.tmp.dir = "${userHome}/.grails/tmp" ``` -------------------------------- ### General Initialization Methods Source: https://grails.apache.org/docs/4.0.12/api/index-all.html Miscellaneous initialization methods. ```APIDOC ## initialize() AbstractProfile ### Description Initializes the profile. ### Method N/A (Method implementation) ### Endpoint N/A ### Parameters None ### Request Example None ### Response None ``` ```APIDOC ## initialize() ClosureValueInitializer ### Description Initializes the closure value initializer. ### Method N/A (Method implementation) ### Endpoint N/A ### Parameters None ### Request Example None ### Response None ``` ```APIDOC ## initialize() DefaultDataBindingSourceRegistry ### Description Initializes the default data binding source registry. ### Method N/A (Method implementation) ### Endpoint N/A ### Parameters None ### Request Example None ### Response None ``` ```APIDOC ## initialize(Object) DefaultProxyHandler ### Description Initializes the default proxy handler. ### Method N/A (Method implementation) ### Endpoint N/A ### Parameters - **target** (Object) - The target object to initialize the proxy for. ### Request Example None ### Response None ``` ```APIDOC ## initialize() DefaultRendererRegistry ### Description Initializes the default renderer registry. ### Method N/A (Method implementation) ### Endpoint N/A ### Parameters None ### Request Example None ### Response None ``` ```APIDOC ## initialize() DefaultUrlMappingsHolder ### Description Initializes the default URL mappings holder. ### Method N/A (Method implementation) ### Endpoint N/A ### Parameters None ### Request Example None ### Response None ``` ```APIDOC ## initialize() DocPublisher ### Description Initializes the documentation publisher. ### Method N/A (Method implementation) ### Endpoint N/A ### Parameters None ### Request Example None ### Response None ``` ```APIDOC ## initialize(GrailsApplication) FilteringCodecsByContentTypeSettings ### Description Initializes the filtering codecs by content type settings. ### Method N/A (Method implementation) ### Endpoint N/A ### Parameters - **grailsApplication** (GrailsApplication) - The Grails application instance. ### Request Example None ### Response None ``` ```APIDOC ## initialize() GradleStep ### Description Initializes the Gradle step. ### Method N/A (Method implementation) ### Endpoint N/A ### Parameters None ### Request Example None ### Response None ``` ```APIDOC ## initialize(InputStream, PrintStream, PrintStream) GrailsConsole ### Description Initializes the Grails console with input and output streams. ### Method N/A (Method implementation) ### Endpoint N/A ### Parameters - **inputStream** (InputStream) - The input stream. - **outputStream** (PrintStream) - The standard output stream. - **errorStream** (PrintStream) - The error output stream. ### Request Example None ### Response None ``` ```APIDOC ## initialize() HalJsonRenderer ### Description Initializes the HAL JSON renderer. ### Method N/A (Method implementation) ### Endpoint N/A ### Parameters None ### Request Example None ### Response None ``` ```APIDOC ## initialize(Object) ProxyHandler ### Description Initializes an existing uninitialized proxy instance. ### Method N/A (Interface method) ### Endpoint N/A ### Parameters - **proxy** (Object) - The proxy instance to initialize. ### Request Example None ### Response None ``` ```APIDOC ## initialize() ValueInitializer ### Description Initializes the value initializer. ### Method N/A (Interface method) ### Endpoint N/A ### Parameters None ### Request Example None ### Response None ``` ```APIDOC ## initializeResourcePath() DefaultLinkGenerator ### Description Initializes the resource path for the link generator. ### Method N/A (Method implementation) ### Endpoint N/A ### Parameters None ### Request Example None ### Response None ``` ```APIDOC ## initializeSpringConfig() BeanBuilder ### Description Initializes the Spring configuration for the bean builder. ### Method N/A (Method implementation) ### Endpoint N/A ### Parameters None ### Request Example None ### Response None ``` ```APIDOC ## initializeBeanBuilderForClassLoader(ClassLoader) BeanBuilder ### Description Initializes the bean builder for a specific class loader. ### Method N/A (Method implementation) ### Endpoint N/A ### Parameters - **classLoader** (ClassLoader) - The class loader to use. ### Request Example None ### Response None ``` ```APIDOC ## initializeFromPropertySources(PropertySources) PropertySourcesConfig ### Description Initializes the configuration from property sources. ### Method N/A (Method implementation) ### Endpoint N/A ### Parameters - **propertySources** (PropertySources) - The property sources to load configuration from. ### Request Example None ### Response None ``` ```APIDOC ## initializeGrailsApplication(ApplicationContext) GrailsApplicationPostProcessor ### Description Initializes the Grails application using the provided ApplicationContext. ### Method N/A (Method implementation) ### Endpoint N/A ### Parameters - **applicationContext** (ApplicationContext) - The Grails application context. ### Request Example None ### Response None ``` ```APIDOC ## initializeGroupAndName(String, boolean) CreateAppCommand ### Description Initializes the group and name for the create-app command. ### Method N/A (Method implementation) ### Endpoint N/A ### Parameters - **appName** (String) - The name of the application. - **force** (boolean) - Whether to force initialization. ### Request Example None ### Response None ``` ```APIDOC ## initializeMultiple(StreamCharBuffer, boolean) StreamCharBuffer.LazyInitializingMultipleWriter ### Description Initializes the underlying writer for the lazy initializing multiple writer. ### Method N/A (Method implementation) ### Endpoint N/A ### Parameters - **buffer** (StreamCharBuffer) - The character buffer. - **flush** (boolean) - Whether to flush after initialization. ### Request Example None ### Response None ``` ```APIDOC ## initializeActionParameters(ClassNode, ASTNode, String, Parameter, SourceUnit, GeneratorContext) ControllerActionTransformer ### Description Initializes action parameters within the controller action transformation. ### Method N/A (Method implementation) ### Endpoint N/A ### Parameters - **classNode** (ClassNode) - The class node. - **astNode** (ASTNode) - The AST node. - **methodName** (String) - The name of the method. - **parameter** (Parameter) - The parameter to initialize. - **sourceUnit** (SourceUnit) - The source unit. - **generatorContext** (GeneratorContext) - The generator context. ### Request Example None ### Response None ``` ```APIDOC ## initializeAndValidateCommandObjectParameter(BlockStatement, ClassNode, ClassNode, ASTNode, String, String, SourceUnit, GeneratorContext) ControllerActionTransformer ### Description Initializes and validates command object parameters. ### Method N/A (Method implementation) ### Endpoint N/A ### Parameters - **blockStatement** (BlockStatement) - The block statement. - **classNode** (ClassNode) - The class node. - **commandObjectNode** (ClassNode) - The command object node. - **astNode** (ASTNode) - The AST node. - **methodName** (String) - The name of the method. - **parameterName** (String) - The name of the parameter. - **sourceUnit** (SourceUnit) - The source unit. - **generatorContext** (GeneratorContext) - The generator context. ### Request Example None ### Response None ``` ```APIDOC ## initializeCommandObjectParameter(BlockStatement, ClassNode, String, SourceUnit) ControllerActionTransformer ### Description Initializes command object parameters. ### Method N/A (Method implementation) ### Endpoint N/A ### Parameters - **blockStatement** (BlockStatement) - The block statement. - **classNode** (ClassNode) - The class node. - **parameterName** (String) - The name of the parameter. - **sourceUnit** (SourceUnit) - The source unit. ### Request Example None ### Response None ``` ```APIDOC ## initializeMethodParameter(ClassNode, BlockStatement, ASTNode, String, Parameter, SourceUnit, GeneratorContext) ControllerActionTransformer ### Description Initializes method parameters. ### Method N/A (Method implementation) ### Endpoint N/A ### Parameters - **classNode** (ClassNode) - The class node. - **blockStatement** (BlockStatement) - The block statement. - **astNode** (ASTNode) - The AST node. - **methodName** (String) - The name of the method. - **parameter** (Parameter) - The parameter to initialize. - **sourceUnit** (SourceUnit) - The source unit. - **generatorContext** (GeneratorContext) - The generator context. ### Request Example None ### Response None ``` ```APIDOC ## initializePrimitiveOrTypeWrapperParameter(ClassNode, BlockStatement, Parameter, String) ControllerActionTransformer ### Description Initializes primitive or type wrapper parameters. ### Method N/A (Method implementation) ### Endpoint N/A ### Parameters - **classNode** (ClassNode) - The class node. - **blockStatement** (BlockStatement) - The block statement. - **parameter** (Parameter) - The parameter to initialize. - **parameterName** (String) - The name of the parameter. ### Request Example None ### Response None ``` ```APIDOC ## initializeStringParameter(ClassNode, BlockStatement, Parameter, String) ControllerActionTransformer ### Description Initializes string parameters. ### Method N/A (Method implementation) ### Endpoint N/A ### Parameters - **classNode** (ClassNode) - The class node. - **blockStatement** (BlockStatement) - The block statement. - **parameter** (Parameter) - The parameter to initialize. - **parameterName** (String) - The name of the parameter. ### Request Example None ### Response None ``` -------------------------------- ### Generate Controller, Test, and Views Source: https://grails.apache.org/docs/4.0.12/guide/gettingStarted.html Use the 'generate-all' command to quickly generate the skeleton of an application, including a controller, its unit test, and associated views for a given domain class. ```bash grails generate-all helloworld.Book ``` -------------------------------- ### Grails Plugin Descriptor Example Source: https://grails.apache.org/docs/4.0.12/guide/plugins.html This is a basic example of a Grails plugin descriptor class. All plugins must have such a class to be recognized. It defines metadata and hooks into plugin extension points. ```groovy import grails.plugins.* class ExampleGrailsPlugin extends Plugin { ... } ``` -------------------------------- ### Create unit test command usage syntax Source: https://grails.apache.org/docs/4.0.12/ref/Command%20Line/create-unit-test.html Shows the standard syntax for the create-unit-test command. ```bash grails create-unit-test <> ``` -------------------------------- ### init() Method Source: https://grails.apache.org/docs/4.0.12/api/org/grails/spring/context/annotation/GrailsContextNamespaceHandler.html Initializes the namespace handler configuration. ```APIDOC ## init() ### Description Initializes the namespace handler, setting up the custom component-scan behavior that ignores Groovy closures. ### Method void ### Response - **void** - This method does not return a value. ``` -------------------------------- ### Grails JSON View Example Source: https://grails.apache.org/docs/4.0.12/guide/theWebLayer.html Example of a Grails JSON view (`.gson`) that iterates over a list of `Book` objects and outputs their titles. It demonstrates how to access the model variable `bookList` passed from the controller. ```groovy @Field List bookList = [] json bookList, { Book book -> title book.title } ``` -------------------------------- ### Find Book by Example Source: https://grails.apache.org/docs/4.0.12/ref/Domain%20Classes/find.html Query for a book by creating an instance of the Book class and setting properties to match. This simplifies queries where you are matching exact values. ```groovy // query by example def example = new Book(author: "Dan Brown") Book.find(example) ``` -------------------------------- ### Grails Controller Example Source: https://grails.apache.org/docs/4.0.12/ref/Plug-ins/controllers.html A basic Grails controller demonstrating how to list books. Ensure the Book domain class is defined. ```groovy class BookController { def list() { [books:Book.list()] } } ``` -------------------------------- ### getExpandoMetaClass Source: https://grails.apache.org/docs/4.0.12/api/grails/util/GrailsClassUtils.html Gets the ExpandoMetaClass for a given class. ```APIDOC ## @java.lang.SuppressWarnings("rawtypes") public static groovy.lang.MetaClass getExpandoMetaClass(java.lang.Class clazz) ### Description Gets the ExpandoMetaClass for a given class. ### Parameters - **clazz** (java.lang.Class) - Required - The class to get the ExpandoMetaClass for. ### Returns The ExpandoMetaClass for the given class. ``` -------------------------------- ### Configure YML and System Properties Source: https://grails.apache.org/docs/4.0.12/guide/conf.html Examples for referencing system properties in YAML and configuring build tasks to pass system properties. ```YAML production: dataSource: url: '${JDBC_CONNECTION_STRING}' ``` ```Groovy bootRun { systemProperties = System.properties } ``` ```Groovy test { systemProperties = System.properties } ``` -------------------------------- ### trimStart Source: https://grails.apache.org/docs/4.0.12/api/grails/util/GrailsStringUtils.html Trims the specified start sequence from a string. ```APIDOC ## static java.lang.String trimStart(java.lang.String str, java.lang.String start) ### Description Trims the start of the string. ### Parameters - **str** (java.lang.String) - Required - The string to trim. - **start** (java.lang.String) - Required - The start to trim. ### Response - **java.lang.String** - The trimmed string. ``` -------------------------------- ### GET /restful/index Source: https://grails.apache.org/docs/4.0.12/api/index-all.html Lists all resources up to the given maximum. ```APIDOC ## GET /restful/index ### Description Lists all resources up to the given maximum. ### Method GET ### Parameters #### Query Parameters - **max** (Integer) - Required - The maximum number of resources to list. ``` -------------------------------- ### Command usage syntax Source: https://grails.apache.org/docs/4.0.12/ref/Command%20Line/create-domain-class.html The standard syntax for invoking the create-domain-class command. ```bash grails create-domain-class <> ``` -------------------------------- ### Basic chain usage Source: https://grails.apache.org/docs/4.0.12/ref/Controllers/chain.html Demonstrates how to initiate a chain to another action with a model. ```Groovy def shawshankRedemption = new Book(title: 'The Shawshank Redemption') chain(action: "details", model: [book: shawshankRedemption]) ``` -------------------------------- ### GET /datasource/config Source: https://grails.apache.org/docs/4.0.12/api/index-all.html Retrieves the database creation configuration. ```APIDOC ## GET /datasource/config ### Description Returns whether to generate the database with HBM 2 DDL, values can be "create", "create-drop" or "update". ### Method GET ### Endpoint /datasource/config ``` -------------------------------- ### Create Grails Application and Domain Class Source: https://grails.apache.org/docs/4.0.12/guide/gettingStarted.html Use Grails convenience targets to create a new application and a domain class. This example creates an application named 'helloworld' and a domain class 'Book'. ```bash grails create-app helloworld cd helloworld grails create-domain-class book ``` -------------------------------- ### GET /application/metadata Source: https://grails.apache.org/docs/4.0.12/api/index-all.html Retrieves metadata for the current application. ```APIDOC ## GET /application/metadata ### Description Returns the metadata for the current application. ### Method GET ### Endpoint /application/metadata ``` -------------------------------- ### Configure Profile Publishing Source: https://grails.apache.org/docs/4.0.12/guide/profiles.html Set up your Bintray credentials and repository details in build.gradle. ```groovy grailsPublish { user = 'YOUR USERNAME' key = 'YOUR KEY' githubSlug = 'your-repo/your-profile' license = 'Apache-2.0' } ``` -------------------------------- ### GET /JSONArray/length Source: https://grails.apache.org/docs/4.0.12/api/org/grails/web/json/JSONArray.html Returns the number of elements in the JSONArray. ```APIDOC ## GET /JSONArray/length ### Description Get the number of elements in the JSONArray, included nulls. ### Response #### Success Response (200) - **length** (int) - The length (or size). ```