Easy Creating Simple CRUD Web Application using Grails 3

Good morning everyone. Today I will show
you this practicing how to create simple create-read-update-delete application
using Grails 3. Now, for the first step, just open your terminal or console and go to
your project folder right here you can just type “grails create-app” and the last
is the app name right here I will use the name “simple-crud” okay it’s done and now you can go to the
currently created new folders and for using the interactive Grails console, just
type “grails” it takes some seconds to finish. wait… okay it’s done.
so right here you can do anything to create your Grails application for see
listing of the common available and Grails
you just type help and here we go it’s available commands. Okay right now we will
create new domain class with this command. Don’t forget to type your
package name right here I’m using “com.djamware.” and of course the
class name okay it’s created next we have to open
this project with your favorite IDE or text editor you can see right here this is a
projects structure of new Grails 3 application. This is the main or core
application codes it’s an asset for the frontends resources configuration controllers domain and the last thing is
views. Because Grails using MVC base so it will modularity based on the consoles domain
and view. Now we have to take configuration first. Take a
look at “application.yml”. Now you see this is the default configuration of
the database it’s using the default H2 DB It’s a memory based database. Now take a
look to the newly created domain is a “Person.groovy” so we can add some
fields right here. We had only created 3 fields with the same
types that using String and we need to create constraints too. In this case we
have the unique email we have used to constraints an email using email colon true let’s say, now back to terminal and
console we have to generate all of the newly created domains we will generate
controllers and views now it fastly generates it and
now we can directly run the apps now open your browser and press “localhost” right here this is the default generated welcomes page of Grails 3
application as you can see in the left bottom of your screen there is a Person
controllers which they are CRUD functions like here. Just click on it so
you want to direct to the person controllers with default page with an index
which is the list of persons now we’re trying to add new persons again fill an
email address name or email oh now we can check the validation default
validation built-in by Grails 3 for example the all fields are blanks we
just click on create button so you can see required fields must be filled for
an example …we will use bad an email address like this. Click “create” now we can
see the validation so showing an error email address now if you fill all the fields
completely now we click on create buttons. Data will be saved now if we
back to the commo percent to the person list I mean it will show the newly created person. Now let’s create another person Next, we have to click on create it’s redirected to the show person and take a look at the list it’s added which is
to record. Now it’s time to view one of list I try to edit update it’s all change. Now
we try to delete the record it’s showed an alert to make sure if you want to
delete the records so click OK and it’s all gone. OK that it’s, the simple
tutorial to created simple create read update and delete application using
Grails 3. Thank you very much!


Add a Comment

Your email address will not be published. Required fields are marked *