In this post I will make a sample application. I have also provided download option at the end of the post in  zip format.
If this is the first time you are looking into grails then I would suggest you to go through my blog post here and make sure that your grails setup is up and running.
In this sample I will show you how to create a domain class, a controller and also basic CRUD operation using GRAILS scaffolding feature. I will be using grails console for giving all commands and eclipse for doing my code editing.
We will make a sample application for a school. let's say SchoolApp. First step for starting a GRAILS application is creating an application using the create-app command. so go ahead and type the below command.
We will create a domain class named Student. To do this go into the SchoolApp directory and type the below command.
We will create a controller for our Student class. Execute the below command to create a controller.
Next, we are going to run our app. To do this we will execute the below command.
If things go well then you should receive a message like below.
When you click on the StudentController you will be able to do CRUD for Student class.
Grails comes bundled with HSQLDB. In case you want to change it to MYSQL or you want to get some information about various database settings and environments within grails, then you can go through my datasource post here.
The download zip of the code is here.
Once you download the zip file, extract it and go inside the SchoolApp folder. Then do a grails run-app as shown above.
In my next post I will show you how to do Relational Mappings, views of grails (GSP's) etc. Stay tuned.
If you have any suggestions or if you are having any problem in running this sample application, Kindly leave a message and I will get back to you at the earliest.
If this is the first time you are looking into grails then I would suggest you to go through my blog post here and make sure that your grails setup is up and running.
In this sample I will show you how to create a domain class, a controller and also basic CRUD operation using GRAILS scaffolding feature. I will be using grails console for giving all commands and eclipse for doing my code editing.
We will make a sample application for a school. let's say SchoolApp. First step for starting a GRAILS application is creating an application using the create-app command. so go ahead and type the below command.
grails create-app SchoolApp 
We will create a domain class named Student. To do this go into the SchoolApp directory and type the below command.
grails create-domain-class Student
- Student.groovy (grails-app/domain)
- StudentTests.groovy (test/unit)
class Student {
    
   static constraints = {
    }   
}
class Student {
    Integer rollNumber;
    String name;
    Date dob;
    Integer age;    
}
We will create a controller for our Student class. Execute the below command to create a controller.
grails create-controller Student
- StudentController.groovy (grails-app/controllers)
- StudentControllerTests.groovy (grails-app/unit)
class StudentController {
  def index = { }    
}
class StudentController {
  def Scaffold = Student    
}
Next, we are going to run our app. To do this we will execute the below command.
grails run-app
Server failed to start: java.net.BindException: Address already in use
If things go well then you should receive a message like below.
Server running. Browse to http://localhost:8080/SchoolApp
When you click on the StudentController you will be able to do CRUD for Student class.
Grails comes bundled with HSQLDB. In case you want to change it to MYSQL or you want to get some information about various database settings and environments within grails, then you can go through my datasource post here.
The download zip of the code is here.
Once you download the zip file, extract it and go inside the SchoolApp folder. Then do a grails run-app as shown above.
In my next post I will show you how to do Relational Mappings, views of grails (GSP's) etc. Stay tuned.
If you have any suggestions or if you are having any problem in running this sample application, Kindly leave a message and I will get back to you at the earliest.

 
 


