{"id":28481,"date":"2015-12-10T15:00:32","date_gmt":"2015-12-10T13:00:32","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=28481"},"modified":"2023-11-09T15:12:48","modified_gmt":"2023-11-09T13:12:48","slug":"grails-groovy-tutorial","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-groovy-tutorial\/","title":{"rendered":"Grails on Groovy Tutorial"},"content":{"rendered":"<p>Grails is a web development framework integrated with JVM that lets developers to develop applications by using built-in features like integrated ORM, DSL (Domain Specific Languages), runtime and compile time meta programming, and concurrent programming.<\/p>\n<p>In this tutorial, I will show you how to develop Grails application step by step with extra theoretical informations about Grails.<br \/>\n<span data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;&quot;}\" data-sheets-userformat=\"{&quot;2&quot;:515,&quot;3&quot;:{&quot;1&quot;:0},&quot;4&quot;:{&quot;1&quot;:2,&quot;2&quot;:16777215},&quot;12&quot;:0}\">[ulp id=&#8217;kHqyxwGNoyzYAfPN&#8217;]<\/span><\/p>\n<div class=\"toc\">\n<h3>Table Of Contents<\/h3>\n<dl>\n<dt><a href=\"#development_environment_setup\">1. Development Environment Setup<\/a><\/dt>\n<dd>\n<dl>\n<dt><a href=\"#jdk_install\">1.1. JDK Install<\/a><\/dt>\n<dt><a href=\"#groovy_install\">1.2. Groovy Install<\/a><\/dt>\n<dt><a href=\"#grails_install\">1.3. Grails Install<\/a><\/dt>\n<dt><a href=\"#environment_vaiables\">1.4. Environment Variables<\/a><\/dt>\n<dt><a href=\"#groovy_grails_tool_suite\">1.5. Groovy\/Grails Tool Suite<\/a><\/dt>\n<dt><a href=\"#running_first_application\">1.6. Running First Application<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dt><a href=\"#mvc_structure\">2. MVC Structure<\/a><\/dt>\n<dt><a href=\"#controllers\">3. Controllers<\/a><\/dt>\n<dt><a href=\"#views\">4. Views<\/a><\/dt>\n<dd>\n<dl>\n<dt><a href=\"#groovy_server_pages\">4.1. Groovy Server Pages<\/a><\/dt>\n<dt><a href=\"#layouts\">4.2. Layouts<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dt><a href=\"#models_and_gorm\">5. Models and GORM<\/a><\/dt>\n<dd>\n<dl>\n<dt><a href=\"#hql_queries\">5.1. HQL Queries<\/a><\/dt>\n<dt><a href=\"#form_submission\">5.2. Form Submission<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dt><a href=\"#scaffolding\">6. Scaffolding<\/a><\/dt>\n<dt><a href=\"#application_services\">7. Application Service Layer<\/a><\/dt>\n<dt><a href=\"#conclusion\">8. Conclusion<\/a><\/dt>\n<\/dl>\n<\/div>\n<h2><a name=\"development_environment_setup\"><\/a>1. Development Environment Setup<\/h2>\n<p>In this section we will install JDK 8, Grails, Groovy\/Grails Tool Suite and make some environmental configurations to be able to use those tools. At the end, we will run our first sample application. By the way, I will proceed my installation with Mac OSX, and this means I will give you the clue here and you can find documentation about how to install it according to your operating system.<\/p>\n<h3><a name=\"jdk_install\"><\/a>1.1. JDK Install<\/h3>\n<p>Since Grails runs on JVM, we need to install JDK on our environment. Go to JDK download page <a href=\"http:\/\/www.oracle.com\/technetwork\/java\/javase\/downloads\/jdk8-downloads-2133151.html\" target=\"_blank\" rel=\"noopener\">here<\/a> and download JDK 8 according to your operating system and architecture. After download, you need to specify <code>JAVA_HOME<\/code> environment variable as JDK home directory. You can also add <code>$JAVA_HOME\/bin<\/code> path to your <code>PATH<\/code> to run java on command line. Now, our environment knows how to use java, let&#8217;s continue with Grails installation<\/p>\n<h3><a name=\"groovy_install\"><\/a>1.2. Groovy Install<\/h3>\n<p>In order to install Groovy, you can go <a href=\"http:\/\/www.groovy-lang.org\/download.html\" target=\"_blank\" rel=\"noopener\">here<\/a> to download Groovy package.<\/p>\n<p><figure id=\"attachment_28546\" aria-describedby=\"caption-attachment-28546\" style=\"width: 860px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/11\/grails_on_groovy_2.jpg\"><img decoding=\"async\" class=\"wp-image-28546 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/11\/grails_on_groovy_2.jpg\" alt=\"Groovy Download Page\" width=\"860\" height=\"630\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/11\/grails_on_groovy_2.jpg 860w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/11\/grails_on_groovy_2-300x220.jpg 300w\" sizes=\"(max-width: 860px) 100vw, 860px\" \/><\/a><figcaption id=\"caption-attachment-28546\" class=\"wp-caption-text\">Groovy Download Page<\/figcaption><\/figure><\/p>\n<h3><a name=\"grails_install\"><\/a>1.3. Grails Install<\/h3>\n<p>Go to Grails download page <a href=\"https:\/\/grails.org\/download.html\" target=\"_blank\" rel=\"noopener\">here<\/a> and download latest Grails package.<\/p>\n<p><figure id=\"attachment_28545\" aria-describedby=\"caption-attachment-28545\" style=\"width: 860px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/11\/grails_on_groovy_1.jpg\"><img decoding=\"async\" class=\"wp-image-28545 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/11\/grails_on_groovy_1.jpg\" alt=\"Grails Download Page\" width=\"860\" height=\"630\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/11\/grails_on_groovy_1.jpg 860w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/11\/grails_on_groovy_1-300x220.jpg 300w\" sizes=\"(max-width: 860px) 100vw, 860px\" \/><\/a><figcaption id=\"caption-attachment-28545\" class=\"wp-caption-text\">Grails Download Page<\/figcaption><\/figure><\/p>\n<p>After package download, extract the download content to folder you desired. We will use jdk and grails folders for environment variable setting.<\/p>\n<h3><a name=\"environment_vaiables\"><\/a>1.4. Environment Variables<\/h3>\n<p>We have downloaded the JDK 8 and Grails, and the current version of JDK of mine is JDK <code>1.8.0_51<\/code> and Grails is <code>3.0.9<\/code>, lastly Groovy 2.4.5. So, you need to set following environment variables;<\/p>\n<p><code>JAVA_HOME=\"\/path\/to\/jdk_1.8.0_51\"<\/code><br \/>\n<code>GROOVY_HOME=\"\/path\/to\/groovy-2.4.5\"<\/code><br \/>\n<code>GRAILS_HOME=\"\/path\/to\/grails-3.0.9\"<\/code><\/p>\n<p>Also, you need to add those home variables to the path if you want like below;<\/p>\n<p><code>PATH=$PATH:$JAVA_HOME\/bin<\/code><br \/>\n<code>PATH=$PATH:$GROOVY_HOME\/bin<\/code><br \/>\n<code>PATH=$PATH:$GRAILS_HOME\/bin<\/code><\/p>\n<p>Remember that, all the environment settings above is Linux specific, you need to use os specific environment setting operation for your operating system.<\/p>\n<h3><a name=\"groovy_grails_tool_suite\"><\/a>1.5. Grails\/Groovy Tool Suite<\/h3>\n<p>Groovy\/Grails Tool Suite is the most used IDE for Grails development. You can go grab from <a href=\"https:\/\/spring.io\/tools\/ggts\" target=\"_blank\" rel=\"noopener\">here<\/a>. After download, you can see executable inside ggts bundle folder and double click to open IDE. It will ask you the workspace before creating projects.<\/p>\n<p><figure id=\"attachment_28551\" aria-describedby=\"caption-attachment-28551\" style=\"width: 860px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/11\/grails_on_groovy_3.jpg\"><img decoding=\"async\" class=\"wp-image-28551 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/11\/grails_on_groovy_3.jpg\" alt=\"GGTS Workspace\" width=\"860\" height=\"630\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/11\/grails_on_groovy_3.jpg 860w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/11\/grails_on_groovy_3-300x220.jpg 300w\" sizes=\"(max-width: 860px) 100vw, 860px\" \/><\/a><figcaption id=\"caption-attachment-28551\" class=\"wp-caption-text\">GGTS Workspace<\/figcaption><\/figure><\/p>\n<p>Now, we need to be sure about GGTS knows your JRE and Grails installation. In order to check JRE configuration on GGTS, Go to <strong>Preferences<\/strong><\/p>\n<p><figure id=\"attachment_28552\" aria-describedby=\"caption-attachment-28552\" style=\"width: 860px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/11\/grails_on_groovy_4.jpg\"><img decoding=\"async\" class=\"wp-image-28552 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/11\/grails_on_groovy_4.jpg\" alt=\"GGTS Preferences\" width=\"860\" height=\"630\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/11\/grails_on_groovy_4.jpg 860w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/11\/grails_on_groovy_4-300x220.jpg 300w\" sizes=\"(max-width: 860px) 100vw, 860px\" \/><\/a><figcaption id=\"caption-attachment-28552\" class=\"wp-caption-text\">GGTS Preferences<\/figcaption><\/figure><\/p>\n<p>And then check <strong>Installed JREs<\/strong>. You need to see JRE path if you successfully defined <code>JAVA_HOME<\/code>, if not, you need to point out installed JRE location.<\/p>\n<p><figure id=\"attachment_30090\" aria-describedby=\"caption-attachment-30090\" style=\"width: 820px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_6.jpg\"><img decoding=\"async\" class=\"wp-image-30090 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_6.jpg\" alt=\"GGTS Installed JREs\" width=\"820\" height=\"601\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_6.jpg 820w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_6-300x220.jpg 300w\" sizes=\"(max-width: 820px) 100vw, 820px\" \/><\/a><figcaption id=\"caption-attachment-30090\" class=\"wp-caption-text\">GGTS Installed JREs<\/figcaption><\/figure><\/p>\n<p>It is same for Grails. Go to <strong>Preferences<\/strong> and then <strong>Grails<\/strong>. You need to point Grails installation location if it is not listed on the screen.<\/p>\n<p><figure id=\"attachment_28554\" aria-describedby=\"caption-attachment-28554\" style=\"width: 860px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/11\/grails_on_groovy_6.jpg\"><img decoding=\"async\" class=\"wp-image-28554 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/11\/grails_on_groovy_6.jpg\" alt=\"GGTS Grails\" width=\"860\" height=\"630\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/11\/grails_on_groovy_6.jpg 860w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/11\/grails_on_groovy_6-300x220.jpg 300w\" sizes=\"(max-width: 860px) 100vw, 860px\" \/><\/a><figcaption id=\"caption-attachment-28554\" class=\"wp-caption-text\">GGTS Grails<\/figcaption><\/figure><\/p>\n<p>Now, we are able to create our first application.<\/p>\n<h3><a name=\"running_first_application\"><\/a>1.6. Running First Application<\/h3>\n<p>In order to create Grails project, go to <strong>File &gt; New &gt; Grails Project<\/strong><\/p>\n<p><figure id=\"attachment_30091\" aria-describedby=\"caption-attachment-30091\" style=\"width: 860px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_10.jpg\"><img decoding=\"async\" class=\"wp-image-30091 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_10.jpg\" alt=\"GGTS New Project\" width=\"860\" height=\"620\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_10.jpg 860w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_10-300x216.jpg 300w\" sizes=\"(max-width: 860px) 100vw, 860px\" \/><\/a><figcaption id=\"caption-attachment-30091\" class=\"wp-caption-text\">GGTS New Project<\/figcaption><\/figure><\/p>\n<p>Provide a name for new project and click <strong>Finish<\/strong> to create new project.<\/p>\n<p><figure id=\"attachment_30092\" aria-describedby=\"caption-attachment-30092\" style=\"width: 860px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_11.jpg\"><img decoding=\"async\" class=\"wp-image-30092 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_11.jpg\" alt=\"GGTS Project Name\" width=\"860\" height=\"504\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_11.jpg 860w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_11-300x176.jpg 300w\" sizes=\"(max-width: 860px) 100vw, 860px\" \/><\/a><figcaption id=\"caption-attachment-30092\" class=\"wp-caption-text\">GGTS Project Name<\/figcaption><\/figure><\/p>\n<p>You will see a project structure like below after project creation.<\/p>\n<p><figure id=\"attachment_30093\" aria-describedby=\"caption-attachment-30093\" style=\"width: 860px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_12.jpg\"><img decoding=\"async\" class=\"wp-image-30093 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_12.jpg\" alt=\"GGTS Project Structure\" width=\"860\" height=\"688\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_12.jpg 860w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_12-300x240.jpg 300w\" sizes=\"(max-width: 860px) 100vw, 860px\" \/><\/a><figcaption id=\"caption-attachment-30093\" class=\"wp-caption-text\">GGTS Project Structure<\/figcaption><\/figure><\/p>\n<p>In order to run application click run grails button in the toolbar like below.<\/p>\n<p><figure id=\"attachment_30094\" aria-describedby=\"caption-attachment-30094\" style=\"width: 860px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_13.jpg\"><img decoding=\"async\" class=\"wp-image-30094 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_13.jpg\" alt=\"GGTS Run Project\" width=\"860\" height=\"135\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_13.jpg 860w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_13-300x47.jpg 300w\" sizes=\"(max-width: 860px) 100vw, 860px\" \/><\/a><figcaption id=\"caption-attachment-30094\" class=\"wp-caption-text\">GGTS Run Project<\/figcaption><\/figure><\/p>\n<p>You will see a popup to execute specific task, enter <strong>run-app<\/strong> and click <strong>Enter<\/strong> to run project.<\/p>\n<p><figure id=\"attachment_30095\" aria-describedby=\"caption-attachment-30095\" style=\"width: 860px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_14.jpg\"><img decoding=\"async\" class=\"wp-image-30095 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_14.jpg\" alt=\"GGTS run-app task\" width=\"860\" height=\"207\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_14.jpg 860w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_14-300x72.jpg 300w\" sizes=\"(max-width: 860px) 100vw, 860px\" \/><\/a><figcaption id=\"caption-attachment-30095\" class=\"wp-caption-text\">GGTS run-app task<\/figcaption><\/figure><\/p>\n<p>Now you can see running project by going this url: <code>http:\/\/localhost:8080\/HelloGrails<\/code>. The application is running on port 8080 and context path is same with name of your project name.<\/p>\n<h2><a name=\"mvc_structure\"><\/a>2. MVC Structure<\/h2>\n<p>Nearly all of us know what is MVC pattern is, and Grails also uses MVC pattern to setup a basic web application in order to write clean code. Let&#8217;s have a look at MVC structure in Grails together.<\/p>\n<p><strong>Model<\/strong> helps us to define our business model to handle data representation and handling. <strong>View<\/strong> is for showing data to end users. <strong>Controller<\/strong> helps us to transfer data between <strong>Model<\/strong> and <strong>View<\/strong>. By using those theoretical informations, we can proceed to some examples.<\/p>\n<p>Let say that you have a model called User to handle user specific data. We can implement it like below.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p><span style=\"text-decoration: underline;\"><em>User.groovy<\/em><\/span><\/p>\n<pre class=\"brush:java\">class User {\n    String name\n    String email\n    String password\n}\n<\/pre>\n<p>If you want to fetch some user data from datasource and display it on the view, you need to apply operation in controller section. Let say that it is like below.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>UserController.groovy<\/em><\/span><\/p>\n<pre class=\"brush:java\">class UserController {\n    def list() {\n        def userList = User.list()\n        [userList:userList]\n    }\n}\n<\/pre>\n<p>Here we are simply getting the list of users through <code>Customer<\/code> domain model to be able to use in controller. There is a naming convention in Grails that, whenever you go to <code>\/user\/list<\/code> , <code>list<\/code> method inside <code>UserController<\/code> will be automatically be invoked. I mean that the pattern is;<\/p>\n<p><code>{url_section_1}\/{url_section_2}<\/code> =&gt; <code>{url_section_1}Controller.groovy<\/code> and <code>{url_section_2}<\/code> action method. Also, the rendered view has a naming convention, in a way that it has same name with actions inside controllers. For example, when you go to <code>\/user\/list<\/code>, <code>list.gsp<\/code> automatically will be rendered. In controllers, we are passing model data to the views, so you can use following code to show model data to end users by make it rendered inside view layer.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>list.gsp<\/em><\/span><\/p>\n<pre class=\"brush:groovy\">&lt;ul&gt;\n   &lt;g:each in=\"${userList}\" var=\"user\"&gt;\n\t&lt;li&gt;${user.name}, ${user.email}&lt;\/li&gt;\n   &lt;\/g:each&gt;\n&lt;\/ul&gt;\n<\/pre>\n<p>This will render html something like below<\/p>\n<pre class=\"brush:html\">&lt;ul&gt;\n\t&lt;li&gt;John, john@gmail.com&lt;\/li&gt;\n&lt;\/ul&gt;\n&lt;ul&gt;\n\t&lt;li&gt;Doe, doe@gmail.com&lt;\/li&gt;\n&lt;\/ul&gt;\n<\/pre>\n<h2><a name=\"controllers\"><\/a>3. Controllers<\/h2>\n<p>We have already seen how a controller structure looks like, now let&#8217;s create a simple controller by using GGTS. Let say that, we want to create a controller in order to perform user related operations. In order to create a controller, <strong>Right-Click<\/strong> on project and <strong>New &gt; Controller<\/strong> as below.<\/p>\n<p><figure id=\"attachment_30124\" aria-describedby=\"caption-attachment-30124\" style=\"width: 860px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_15.jpg\"><img decoding=\"async\" class=\"wp-image-30124 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_15.jpg\" alt=\"GGTS Create Controller\" width=\"860\" height=\"563\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_15.jpg 860w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_15-300x196.jpg 300w\" sizes=\"(max-width: 860px) 100vw, 860px\" \/><\/a><figcaption id=\"caption-attachment-30124\" class=\"wp-caption-text\">GGTS Create Controller<\/figcaption><\/figure><\/p>\n<p>I assume you have provided controller name as <code>UserController<\/code> and you will end up with following screen.<\/p>\n<p><figure id=\"attachment_30125\" aria-describedby=\"caption-attachment-30125\" style=\"width: 860px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_16.jpg\"><img decoding=\"async\" class=\"wp-image-30125 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_16.jpg\" alt=\"GGTS Sample Controller\" width=\"860\" height=\"390\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_16.jpg 860w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_16-300x136.jpg 300w\" sizes=\"(max-width: 860px) 100vw, 860px\" \/><\/a><figcaption id=\"caption-attachment-30125\" class=\"wp-caption-text\">GGTS Sample Controller<\/figcaption><\/figure><\/p>\n<p>When you look at screen, you can see that a default action called <code>index()<\/code> created and also user related view folder is created in <code>views<\/code> folder. Let say that, you want to display something when user go to default action of user controller. You can use following to do so.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>UserController.groovy<\/em><\/span><\/p>\n<pre class=\"brush:groovy\">package hellograils\n\nclass UserController {\n\n    def index() { \n\t\trender \"This is the index page of UserController\"\n\t}\n}\n<\/pre>\n<p>When you go to <code>http:\/\/localhost:8080\/HelloGrails\/user<\/code>, default action <code>index()<\/code> will be executed and the text will be rendered on the browser by using <code>render()<\/code> function.<\/p>\n<p>Let&#8217;s do another example that whenever you go to user view action with a username provided in the url, it will be displayed on the page. In order to get url params in Grails, you can use <code>params.key<\/code>. You can see full code to fetch username and display it on the page below.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>UserController.groovy<\/em><\/span><\/p>\n<pre class=\"brush:groovy\">package hellograils\n\nclass UserController {\n\n    def view() { \n\t\trender \"Hello, ${params.username}\"\n\t}\n}\n<\/pre>\n<p>When you go to <code>http:\/\/localhost:8080\/HelloGrails\/user\/view?username=huseyinbabal<\/code> you will see following.<\/p>\n<p><figure id=\"attachment_30126\" aria-describedby=\"caption-attachment-30126\" style=\"width: 860px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_18.jpg\"><img decoding=\"async\" class=\"wp-image-30126 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_18.jpg\" alt=\"Grails Url Params\" width=\"860\" height=\"277\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_18.jpg 860w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_18-300x97.jpg 300w\" sizes=\"(max-width: 860px) 100vw, 860px\" \/><\/a><figcaption id=\"caption-attachment-30126\" class=\"wp-caption-text\">Grails Url Params<\/figcaption><\/figure><\/p>\n<h2><a name=\"views\"><\/a>4. Views<\/h2>\n<p>Views layer in a simple web application is used for the interaction with end user. You can use views to show your domain data after you have applied some rules inside your controller. In previous section we have created controller and it has automatically created specific view folder. We will use Groovy Server Pages to render and show your business data to end users in your Grails application.<\/p>\n<h3><a name=\"groovy_server_pages\"><\/a>4.1. Groovy Server Pages<\/h3>\n<p>Groovy Server Pages (GSP) is the default template engine for the Grails. It is very simple and similar to JSP that allows you to show your data to user after rendered on server side. Let&#8217;s have a look at some examples for usage.<\/p>\n<p>If you want to show user related data on web page, you need a controller that we have already created in previous sections and you will need a specific view file. We have created an action called view() on UserController and let say that you want to display user data in view. You need to assign user model to view firs like below.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>UserController.groovy<\/em><\/span><\/p>\n<pre class=\"brush:groovy\">package hellograils\n\nclass UserController {\n\n    def view() {\n        def user = [name: \"John\", surname: \"Doe\", email: \"johndoe@gmail.com\"]\n\t    [user: user]\n    }\n}\n<\/pre>\n<p>In above code, we simply created a Groovy map for user properties and returned as map. In Groovy, the last line is returned by default. The key name returned in this function is <code>user<\/code>, this means, you can access user data in the view by using <code>user<\/code>. Since the action name is <code>view<\/code>, we need to have a view file called <code>view.gsp<\/code> in <strong>views &gt; user<\/strong> folder. In order to create a GSP file, <strong>Right-Click<\/strong> on the project and <strong>New &gt; Groovy Server Pages<\/strong> like below.<\/p>\n<p><figure id=\"attachment_30128\" aria-describedby=\"caption-attachment-30128\" style=\"width: 860px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_19.jpg\"><img decoding=\"async\" class=\"wp-image-30128 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_19.jpg\" alt=\"GGTS Create GSP\" width=\"860\" height=\"571\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_19.jpg 860w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_19-300x199.jpg 300w\" sizes=\"(max-width: 860px) 100vw, 860px\" \/><\/a><figcaption id=\"caption-attachment-30128\" class=\"wp-caption-text\">GGTS Create GSP<\/figcaption><\/figure><\/p>\n<p>After view file creation, add following gsp file content to <code>view.gsp<\/code> file.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>view.gsp<\/em><\/span><\/p>\n<pre class=\"brush:html\">&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n\t&lt;head&gt;\n\t\t&lt;meta name=\"layout\" content=\"main\"\/&gt;\n\t\t&lt;title&gt;User Profile&lt;\/title&gt;\n\t&lt;\/head&gt;\n\t&lt;body&gt;\n\t\t&lt;table&gt;\n\t\t\t&lt;tr&gt;\n\t\t\t\t&lt;td&gt;Name: &lt;\/td&gt;&lt;td&gt;${user.name}&lt;\/td&gt;\n\t\t\t&lt;\/tr&gt;\n\t\t\t&lt;tr&gt;\n\t\t\t\t&lt;td&gt;Surname: &lt;\/td&gt;&lt;td&gt;${user.surname}&lt;\/td&gt;\n\t\t\t&lt;\/tr&gt;\n\t\t\t&lt;tr&gt;\n\t\t\t\t&lt;td&gt;Email: &lt;\/td&gt;&lt;td&gt;${user.email}&lt;\/td&gt;\n\t\t\t&lt;\/tr&gt;\n\t\t&lt;\/table&gt;\n\t&lt;\/body&gt;\n&lt;\/html&gt;\n<\/pre>\n<p>In this file, as you can see we have used <code>user.{}<\/code> notation to access user related data passed from controller. Another important point in this view file is <code><\/code>. Here we are saying that, this file will be use the layout called main. And layout templates exists under <strong>views &gt; layouts<\/strong> folder. When you go to <code>http:\/\/localhost:8080\/HelloGrails\/user\/view<\/code>, you will see following screen.<\/p>\n<p><figure id=\"attachment_30129\" aria-describedby=\"caption-attachment-30129\" style=\"width: 860px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_20.jpg\"><img decoding=\"async\" class=\"wp-image-30129 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_20.jpg\" alt=\"Grails View Layout\" width=\"860\" height=\"300\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_20.jpg 860w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_20-300x105.jpg 300w\" sizes=\"(max-width: 860px) 100vw, 860px\" \/><\/a><figcaption id=\"caption-attachment-30129\" class=\"wp-caption-text\">Grails View Layout<\/figcaption><\/figure><\/p>\n<p>If you haven&#8217;t used a layout, you would see user detail in a blank page without any layout like below.<\/p>\n<p><figure id=\"attachment_30130\" aria-describedby=\"caption-attachment-30130\" style=\"width: 860px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_21.jpg\"><img decoding=\"async\" class=\"wp-image-30130 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_21.jpg\" alt=\"Grails View Without Layout\" width=\"860\" height=\"358\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_21.jpg 860w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_21-300x125.jpg 300w\" sizes=\"(max-width: 860px) 100vw, 860px\" \/><\/a><figcaption id=\"caption-attachment-30130\" class=\"wp-caption-text\">Grails View Without Layout<\/figcaption><\/figure><\/p>\n<h3><a name=\"layouts\"><\/a>4.2. Layouts<\/h3>\n<p>Layouts are used for the commonly used areas for different views. Let say that, you have 10 views and all those views contains left menu, footer, and header section. You don&#8217;t need to define those sections for each views, you can create a layout and make those views use this layout instead. In order to create layout, create a file under <strong>views &gt; layouts<\/strong>. By default, we have <code>main.gsp<\/code>. In order to use layout inside view file, you can use following example.<\/p>\n<pre class=\"brush:html\">&lt;meta name=\"layout\" content=\"main\"\/&gt;\n<\/pre>\n<h2><a name=\"models_and_gorm\"><\/a>5. Models and GORM<\/h2>\n<p>Models are used for defining your business data in software world. Let say that you have user data and want to define it in your application. You can use User model to make CRUD operations along side the database or any other external data store. You can see a sample model below.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>User.groovy<\/em><\/span><\/p>\n<pre class=\"brush:groovy\">class User {\n    String name\n    String surname\n    String email\n}\n<\/pre>\n<p>While we are performing database related operations, we will use this model. If you are already familiar with ORM, you know what is GORM too. GORM is the ORM layer for the Grails applications, and it isolates your db layer operations from your application. You can use domain models to perform db operations instead of constructing and executing SQL queries.<\/p>\n<h3><a name=\"hql_queries\"><\/a>5.1. HQL Queries<\/h3>\n<p>Grails uses Embedded <a href=\"https:\/\/en.wikipedia.org\/wiki\/H2_(DBMS)\">H2 Database<\/a> by default, that means you can directly use db related operations by simply defining your domain model. If you want to use custom datasource, you can configure <code>DataSource.groovy<\/code> under <strong>conf<\/strong> folder file to connect custom database. We will continue with H2 Database to keep context simple.[ulp id='kHqyxwGNoyzYAfPN']<\/p>\n<p>In order to create user in database, you can use following.<\/p>\n<pre class=\"brush:groovy\">    User user = new User();\n    user.name = \"Huseyin\"\n    user.surname = \"BABAL\"\n    user.email = \"huseyin@gmail.com\"\n    user.save()\n<\/pre>\n<p>In above example, we are simply creating instance of the <code>User<\/code> model and then setting field values and finally performing <code>save()<\/code> function on final <code>User<\/code> model. In order to get specific User data, you can simply execute following code.<\/p>\n<pre class=\"brush:groovy\">    User user = User.get(1)\n<\/pre>\n<p>You can also update fetched model by using following.<\/p>\n<pre class=\"brush:groovy\">    User user = User.get(1)\n    user.email = \"huseyinbabal@gmail.com\"\n    user.save()\n<\/pre>\n<p>Here, simply user data is fetched, email information updated on model and user model is persisted to the database. As you can guess, you can delete data by using following.<\/p>\n<pre class=\"brush:groovy\">    User user = User.get(1)\n    user.delete()\n<\/pre>\n<p>You can also perform named query like expression;<\/p>\n<p>Find user by email:<\/p>\n<pre class=\"brush:groovy\">    User user = User.findByEmail(\"john@gmail.com\")\n<\/pre>\n<p>Find by name and surname:<\/p>\n<pre class=\"brush:groovy\">    User user = User.findByNameAndSurname(\"john\", \"doe\")\n<\/pre>\n<p>List all the users that has name:<\/p>\n<pre class=\"brush:groovy\">    User user = User.findAllByName(\"john\")\n<\/pre>\n<p>Named queries are easy to use, just be careful about using correct field name on named conditions. For example, the email field is <code>email<\/code> in <code>User<\/code> class, and you need to use <code>findByEmail<\/code> not <code>findByemail<\/code>.<\/p>\n<h3><a name=\"form_submission\"><\/a>5.2. Form Submission<\/h3>\n<p>We saw how to perform db queries by using HQL and this time let&#8217;s perform some form submission to create, list, and view user on our application. Our first step will be creating a page for user create form. Create a view called <code>userForm.gsp<\/code> and paste following form code inside it.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>userForm.gsp<\/em><\/span><\/p>\n<pre class=\"brush:html\">&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n\t&lt;head&gt;\n\t\t&lt;meta name=\"layout\" content=\"main\"\/&gt;\n\t\t&lt;title&gt;Create New User&lt;\/title&gt;\n\t&lt;\/head&gt;\n\t&lt;body&gt;\n\t\t&lt;g:form controller=\"user\" action=\"create\"&gt;\n\t\t\t&lt;table&gt;\n\t\t\t\t&lt;tr&gt;\n\t\t\t\t\t&lt;td&gt;Name: &lt;\/td&gt;&lt;td&gt;&lt;g:textField name=\"name\"\/&gt;&lt;\/td&gt;\n\t\t\t\t&lt;\/tr&gt;\n\t\t\t\t&lt;tr&gt;\n\t\t\t\t\t&lt;td&gt;Surname: &lt;\/td&gt;&lt;td&gt;&lt;g:textField name=\"surname\"\/&gt;&lt;\/td&gt;\n\t\t\t\t&lt;\/tr&gt;\n\t\t\t\t&lt;tr&gt;\n\t\t\t\t\t&lt;td&gt;Email: &lt;\/td&gt;&lt;td&gt;&lt;g:textField name=\"email\"\/&gt;&lt;\/td&gt;\n\t\t\t\t&lt;\/tr&gt;\n\t\t\t\t&lt;tr&gt;&lt;td colspan=\"2\"&gt;&lt;g:actionSubmit value=\"Create\"\/&gt;&lt;\/td&gt;&lt;\/tr&gt;\n\t\t\t&lt;\/table&gt;\n\t\t&lt;\/g:form&gt;\n\t&lt;\/body&gt;\n&lt;\/html&gt;\n<\/pre>\n<p>In above form we created a form by using Groovy Server Pages as you can see in the tags <code>g:...<\/code>. In this form, we provided the controller and action name to post user form to defined controller and action. When you enter required fields and click Create button, form will be posted to <code>UserController<\/code> controller <code>create<\/code> action. In order to open this form, you can go <code>http:\/\/localhost:8080\/HelloGrails\/user\/userForm<\/code>, and you will see a screen like below.<\/p>\n<p><figure id=\"attachment_30146\" aria-describedby=\"caption-attachment-30146\" style=\"width: 860px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_23.jpg\"><img decoding=\"async\" class=\"wp-image-30146 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_23.jpg\" alt=\"User Create Form\" width=\"860\" height=\"401\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_23.jpg 860w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_23-300x140.jpg 300w\" sizes=\"(max-width: 860px) 100vw, 860px\" \/><\/a><figcaption id=\"caption-attachment-30146\" class=\"wp-caption-text\">User Create Form<\/figcaption><\/figure><\/p>\n<p>As you can see there is an empty action called userForm in <code>UserController<\/code>. This will help us to render specific view with same name which is <code>userForm.gsp<\/code>.<\/p>\n<p>Let&#8217;s implement the create action to handle form post to create user in database. You can use following to get form data and save it to the database.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>UserController.groovy<\/em><\/span><\/p>\n<pre class=\"brush:groovy\">def create() {\n    def user = new User(params)\n    user.save()\n    render \"User created successfully\"\n}\n<\/pre>\n<p>We have created an action called <code>create<\/code> because we have provided action name as create in user form and here we are getting form data by using <code>params<\/code>. Form field names are same as <strong>User<\/strong> class field names, so we directly passed form post body to <strong>User<\/strong> class as constructor. When you click <strong>Create<\/strong> button you will see <strong>User created successfully<\/strong> message<\/p>\n<p>This time, we will list all the users in the database. You can do by first create an action and view called <code>list<\/code> and <code>list.gsp<\/code> respectively. You can see following.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>UserController.groovy<\/em><\/span><\/p>\n<pre class=\"brush:groovy\">def list() {\n    def list = User.list()\n    [userList: list]\n}\n<\/pre>\n<p>and view file content is following.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>list.gsp<\/em><\/span><\/p>\n<pre class=\"brush:html\">&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n\t&lt;head&gt;\n\t\t&lt;meta name=\"layout\" content=\"main\"\/&gt;\n\t\t&lt;title&gt;User List&lt;\/title&gt;\n\t&lt;\/head&gt;\n\t&lt;body&gt;\n\t\t&lt;g:if test=\"${userList.size == 0}\"&gt;\n\t\t\tThere is no user yet, &lt;g:link action=\"userForm\"&gt;Create New User?&lt;\/g:link&gt;\n\t\t&lt;\/g:if&gt;\n\t\t&lt;g:else&gt;\n\t\t\t&lt;table&gt;\n\t\t\t\t&lt;tr&gt;\n\t\t\t\t\t&lt;g:each in=\"${userList}\" var=\"user\"&gt;\n\t\t\t\t\t\t&lt;td&gt;${user.name}&lt;\/td&gt;\n\t\t\t\t\t\t&lt;td&gt;${user.surname}&lt;\/td&gt;\n\t\t\t\t\t\t&lt;td&gt;${user.email}&lt;\/td&gt;\n\t\t\t\t\t\t&lt;td&gt;&lt;g:link action=\"edit\" id=\"${user.id}\"&gt;Edit&lt;\/g:link&gt;&lt;\/td&gt;\n\t\t\t\t\t&lt;\/g:each&gt;\n\t\t\t\t&lt;\/tr&gt;\n\t\t\t&lt;\/table&gt;\n\t\t&lt;\/g:else&gt;\n\t&lt;\/body&gt;\n&lt;\/html&gt;\n<\/pre>\n<p>In controller action, we fetched entire user list and assigned that list to the view with a name <code>userList<\/code>. In view file, we simply checked the size of user list, if it is zero, we have suggested user to create new one, else all the user list rendered on the page like below<\/p>\n<p><figure id=\"attachment_30148\" aria-describedby=\"caption-attachment-30148\" style=\"width: 860px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_24.png\"><img decoding=\"async\" class=\"wp-image-30148 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_24.png\" alt=\"User List\" width=\"860\" height=\"222\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_24.png 860w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_24-300x77.png 300w\" sizes=\"(max-width: 860px) 100vw, 860px\" \/><\/a><figcaption id=\"caption-attachment-30148\" class=\"wp-caption-text\">User List<\/figcaption><\/figure><\/p>\n<p>As you can see, there is an edit link on each user row, and this link is generated by using <code><\/code>. In this element, we have provided action and an id. When you click Edit link, you will go to edit form of user which has id specified in id attribute. Let&#8217;s create <code>editForm<\/code> and <code>edit<\/code> action for user now. You can use following for user edit form.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>editForm.gsp<\/em><\/span><\/p>\n<pre class=\"brush:html\">&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n\t&lt;head&gt;\n\t\t&lt;meta name=\"layout\" content=\"main\"\/&gt;\n\t\t&lt;title&gt;Edit User&lt;\/title&gt;\n\t&lt;\/head&gt;\n\t&lt;body&gt;\n\t\t&lt;g:form controller=\"user\" action=\"update\"&gt;\n\t\t\t&lt;g:hiddenField name=\"id\" value=\"${user.id}\"\/&gt;\n\t\t\t&lt;table&gt;\n\t\t\t\t&lt;tr&gt;\n\t\t\t\t\t&lt;td&gt;Name: &lt;\/td&gt;&lt;td&gt;&lt;g:textField name=\"name\" value=\"${user.name}\"\/&gt;&lt;\/td&gt;\n\t\t\t\t&lt;\/tr&gt;\n\t\t\t\t&lt;tr&gt;\n\t\t\t\t\t&lt;td&gt;Surname: &lt;\/td&gt;&lt;td&gt;&lt;g:textField name=\"surname\" value=\"${user.surname}\"\/&gt;&lt;\/td&gt;\n\t\t\t\t&lt;\/tr&gt;\n\t\t\t\t&lt;tr&gt;\n\t\t\t\t\t&lt;td&gt;Email: &lt;\/td&gt;&lt;td&gt;&lt;g:textField name=\"email\" value=\"${user.email}\"\/&gt;&lt;\/td&gt;\n\t\t\t\t&lt;\/tr&gt;\n\t\t\t\t&lt;tr&gt;&lt;td colspan=\"2\"&gt;&lt;g:actionSubmit value=\"Update\"\/&gt;&lt;\/td&gt;&lt;\/tr&gt;\n\t\t\t&lt;\/table&gt;\n\t\t&lt;\/g:form&gt;\n\t&lt;\/body&gt;\n&lt;\/html&gt;\n<\/pre>\n<p>In this form there is a hidden field called <code>id<\/code> and this will be used for updating user instance from database. When we go to editForm url, the specified action in <code>UserController<\/code> will be executed and user that has an id specified in url will be assigned to <code>editForm<\/code> and form will be populated with current user data. You can see <code>editForm<\/code> action below.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>UserController.groovy<\/em><\/span><\/p>\n<pre class=\"brush:groovy\">    def user = User.get(params.id)\n    [user: user]\n<\/pre>\n<p>Simply, get user by id and then assign it to <code>editForm<\/code>. When you click Update button, updated user data will be posted to the <code>update<\/code> action in <code>UserController<\/code>.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>UserController.groovy<\/em><\/span><\/p>\n<pre class=\"brush:groovy\">    def update() {\n        User user = User.get(params.id)\n        user.properties = params\n        user.save(flush: true)\n        render \"User updated successfully\"\n    }\n<\/pre>\n<p>Here, we get user data first, and update all field values with the data posted from form, and we saved data to database with <code>flush<\/code> parameter to update data in session also. As you can see, it is very easy to update class field values by using <code>user.properties = params<\/code>. We are saying that, update all the fields of user data with form post body.<\/p>\n<h2><a name=\"scaffolding\"><\/a>6. Scaffolding<\/h2>\n<p>You will like this part very much because we will do the magic by using Grails in this section. By using Scaffolding property, we will auto generate forms for CRUD operations by using your domain class and simple controller. Let&#8217;s get started.<\/p>\n<p>Let say that we have another domain class called <code>Product<\/code> and it has following fields.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Product.groovy<\/em><\/span><\/p>\n<pre class=\"brush:groovy\">class Product {\n\tString title\n\tString name\n\tString price\n\tString description\n}\n<\/pre>\n<p>Then create a controller called <code>ProductController<\/code>, and it will have following content.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>ProductController.groovy<\/em><\/span><\/p>\n<pre class=\"brush:groovy\">class ProductController {\n\n    static scaffold = true\n}\n<\/pre>\n<p>And, If you go to <code>http:\/\/localhost:8080\/HelloGrails\/product<\/code>, you will see following.<\/p>\n<p><figure id=\"attachment_30149\" aria-describedby=\"caption-attachment-30149\" style=\"width: 860px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_25.jpg\"><img decoding=\"async\" class=\"wp-image-30149 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_25.jpg\" alt=\"Scaffolding Main Page\" width=\"860\" height=\"290\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_25.jpg 860w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_25-300x101.jpg 300w\" sizes=\"(max-width: 860px) 100vw, 860px\" \/><\/a><figcaption id=\"caption-attachment-30149\" class=\"wp-caption-text\">Scaffolding Main Page<\/figcaption><\/figure><\/p>\n<p>Yes that is true. Grails auto generates form components for CRUD operations by using your domain class. The only thing you need to do is adding <code>static scaffolding = true<\/code> inside your controller belongs to domain class. It uses the field names inside your domain class to setup form like below.<\/p>\n<p><figure id=\"attachment_30150\" aria-describedby=\"caption-attachment-30150\" style=\"width: 860px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_26.jpg\"><img decoding=\"async\" class=\"wp-image-30150 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_26.jpg\" alt=\"Product Create Form\" width=\"860\" height=\"442\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_26.jpg 860w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_26-300x154.jpg 300w\" sizes=\"(max-width: 860px) 100vw, 860px\" \/><\/a><figcaption id=\"caption-attachment-30150\" class=\"wp-caption-text\">Product Create Form<\/figcaption><\/figure><\/p>\n<h2><a name=\"application_service_layer\"><\/a>7. Application Service Layer<\/h2>\n<p>Until this part, we used domain class operations inside the controllers. However, it will be better if we separate our service layers like n-tier applications. For example, in order to create user in database, we can create a UserService and inject it inside controller to user service methods. In order to create Service <strong>Right-Click<\/strong> project and <strong>New &gt; Service<\/strong> give it a name like <strong>UserService<\/strong> and <strong>Finish<\/strong>.<\/p>\n<p><figure id=\"attachment_30151\" aria-describedby=\"caption-attachment-30151\" style=\"width: 860px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_27.jpg\"><img decoding=\"async\" class=\"wp-image-30151 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_27.jpg\" alt=\"GGTS Service\" width=\"860\" height=\"626\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_27.jpg 860w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/grails_on_groovy_27-300x218.jpg 300w\" sizes=\"(max-width: 860px) 100vw, 860px\" \/><\/a><figcaption id=\"caption-attachment-30151\" class=\"wp-caption-text\">GGTS Service<\/figcaption><\/figure><\/p>\n<p>Open up <code>UserService<\/code> and create following method inside it.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>UserService.groovy<\/em><\/span><\/p>\n<pre class=\"brush:groovy\">package hellograils\n\nimport grails.transaction.Transactional\n\n@Transactional\nclass UserService {\n\n    def createUser(String name, String surname, String email) {\n\t\tUser user = new User(name: name, surname: surname, email: email)\n\t\tuser.save()\n\t\tuser\n    }\n}\n<\/pre>\n<p>In order to use this service, we need to inject it inside UserController. Simply inject it by defining it inside controller like below.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>UserController.groovy<\/em><\/span><\/p>\n<pre class=\"brush:groovy\">package hellograils\n\nclass UserController {\n\n    def userService\n    \n    def create() {\n        userService.createUser(params.name, params.surname, params.email)\n        render \"User created successfully\"\n    }    \n}\n<\/pre>\n<p>By doing this, you can easily separate your business logic from your controllers and let controllers very clean and simple.<\/p>\n<h2><a name=\"conclusion\"><\/a>8. Conclusion<\/h2>\n<p>After some theoretical informations and code example, we can say that Grails helps us to create simple web applications in an easy way. It uses the power of Groovy, separates concerns by using MVC pattern, lets you to create views by using Groovy Server Pages, event it auto generates forms with a simple config. Even if you do not have installed database, it is very easy to do db related operations with embedded H2 database with zero config.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example as an Eclipse project here: <span style=\"font-weight: 400;\"><strong><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/HelloGrails.zip\" target=\"_blank\" rel=\"noopener\">HelloGrails<\/a><\/strong><\/span><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Grails is a web development framework integrated with JVM that lets developers to develop applications by using built-in features like integrated ORM, DSL (Domain Specific Languages), runtime and compile time meta programming, and concurrent programming. In this tutorial, I will show you how to develop Grails application step by step with extra theoretical informations about &hellip;<\/p>\n","protected":false},"author":56,"featured_media":27333,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1528],"tags":[1214,982],"class_list":["post-28481","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-grails","tag-grails","tag-groovy"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Grails on Groovy Tutorial - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Grails is a web development framework integrated with JVM that lets developers to develop applications by using built-in features like integrated ORM, DSL\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-groovy-tutorial\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Grails on Groovy Tutorial - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Grails is a web development framework integrated with JVM that lets developers to develop applications by using built-in features like integrated ORM, DSL\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-groovy-tutorial\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2015-12-10T13:00:32+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-11-09T13:12:48+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/grails-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Huseyin Babal\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@huseyinbabal\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Huseyin Babal\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"17 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-groovy-tutorial\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-groovy-tutorial\/\"},\"author\":{\"name\":\"Huseyin Babal\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/a64b2fa737b82194b7dfc39117f4a237\"},\"headline\":\"Grails on Groovy Tutorial\",\"datePublished\":\"2015-12-10T13:00:32+00:00\",\"dateModified\":\"2023-11-09T13:12:48+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-groovy-tutorial\/\"},\"wordCount\":2921,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-groovy-tutorial\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/grails-logo.jpg\",\"keywords\":[\"Grails\",\"groovy\"],\"articleSection\":[\"Grails\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-groovy-tutorial\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-groovy-tutorial\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-groovy-tutorial\/\",\"name\":\"Grails on Groovy Tutorial - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-groovy-tutorial\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-groovy-tutorial\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/grails-logo.jpg\",\"datePublished\":\"2015-12-10T13:00:32+00:00\",\"dateModified\":\"2023-11-09T13:12:48+00:00\",\"description\":\"Grails is a web development framework integrated with JVM that lets developers to develop applications by using built-in features like integrated ORM, DSL\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-groovy-tutorial\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-groovy-tutorial\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-groovy-tutorial\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/grails-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/grails-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-groovy-tutorial\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JVM Languages\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/jvm-languages\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Groovy\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/jvm-languages\/groovy\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Grails\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/jvm-languages\/groovy\/grails\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"Grails on Groovy Tutorial\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/a64b2fa737b82194b7dfc39117f4a237\",\"name\":\"Huseyin Babal\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/Huseyin-Babal-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/Huseyin-Babal-96x96.jpg\",\"caption\":\"Huseyin Babal\"},\"description\":\"Huseyin Babal has deep experience in Full Stack Development since 2007. He is mainly developing applications with JAVA, Spring, PHP, NodeJS, AngularJS. He is also interested in DevOps Engineering since 2013 and using AWS, Heroku for Cloud deployment and playing with Docker and Consul for implementing infinite scalable systems. He likes to share his experience in public conferences and perform advanced workshops about Full Stack Development and Devops. He is the author of NodeJS in Action course in Udemy.\",\"sameAs\":[\"http:\/\/huseyinbabal.net\",\"https:\/\/www.linkedin.com\/in\/huseyinbabal\",\"https:\/\/x.com\/huseyinbabal\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/huseyin-babal\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Grails on Groovy Tutorial - Java Code Geeks","description":"Grails is a web development framework integrated with JVM that lets developers to develop applications by using built-in features like integrated ORM, DSL","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-groovy-tutorial\/","og_locale":"en_US","og_type":"article","og_title":"Grails on Groovy Tutorial - Java Code Geeks","og_description":"Grails is a web development framework integrated with JVM that lets developers to develop applications by using built-in features like integrated ORM, DSL","og_url":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-groovy-tutorial\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2015-12-10T13:00:32+00:00","article_modified_time":"2023-11-09T13:12:48+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/grails-logo.jpg","type":"image\/jpeg"}],"author":"Huseyin Babal","twitter_card":"summary_large_image","twitter_creator":"@huseyinbabal","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Huseyin Babal","Est. reading time":"17 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-groovy-tutorial\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-groovy-tutorial\/"},"author":{"name":"Huseyin Babal","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/a64b2fa737b82194b7dfc39117f4a237"},"headline":"Grails on Groovy Tutorial","datePublished":"2015-12-10T13:00:32+00:00","dateModified":"2023-11-09T13:12:48+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-groovy-tutorial\/"},"wordCount":2921,"commentCount":0,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-groovy-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/grails-logo.jpg","keywords":["Grails","groovy"],"articleSection":["Grails"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-groovy-tutorial\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-groovy-tutorial\/","url":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-groovy-tutorial\/","name":"Grails on Groovy Tutorial - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-groovy-tutorial\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-groovy-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/grails-logo.jpg","datePublished":"2015-12-10T13:00:32+00:00","dateModified":"2023-11-09T13:12:48+00:00","description":"Grails is a web development framework integrated with JVM that lets developers to develop applications by using built-in features like integrated ORM, DSL","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-groovy-tutorial\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-groovy-tutorial\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-groovy-tutorial\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/grails-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/grails-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-groovy-tutorial\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"JVM Languages","item":"https:\/\/examples.javacodegeeks.com\/category\/jvm-languages\/"},{"@type":"ListItem","position":3,"name":"Groovy","item":"https:\/\/examples.javacodegeeks.com\/category\/jvm-languages\/groovy\/"},{"@type":"ListItem","position":4,"name":"Grails","item":"https:\/\/examples.javacodegeeks.com\/category\/jvm-languages\/groovy\/grails\/"},{"@type":"ListItem","position":5,"name":"Grails on Groovy Tutorial"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/a64b2fa737b82194b7dfc39117f4a237","name":"Huseyin Babal","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/Huseyin-Babal-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/Huseyin-Babal-96x96.jpg","caption":"Huseyin Babal"},"description":"Huseyin Babal has deep experience in Full Stack Development since 2007. He is mainly developing applications with JAVA, Spring, PHP, NodeJS, AngularJS. He is also interested in DevOps Engineering since 2013 and using AWS, Heroku for Cloud deployment and playing with Docker and Consul for implementing infinite scalable systems. He likes to share his experience in public conferences and perform advanced workshops about Full Stack Development and Devops. He is the author of NodeJS in Action course in Udemy.","sameAs":["http:\/\/huseyinbabal.net","https:\/\/www.linkedin.com\/in\/huseyinbabal","https:\/\/x.com\/huseyinbabal"],"url":"https:\/\/examples.javacodegeeks.com\/author\/huseyin-babal\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/28481","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/56"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=28481"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/28481\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/27333"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=28481"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=28481"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=28481"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}