package com.rmigb.controller;

 

 import com.util.ArrayList;

 

 import org.springframework.beans.factory.annotation.Autowired;

 import org.springframework.stereotype.Controller;

 import org.springframework.ui.Model;

 import org.springframework.validation.BindingResult;

 import org.springframework.web.bind.annotation.ModelAttribute;

 import org.springframework.web.bind.annotation.PathVariable;

 import org.springframework.web.bind.annotation.RequestMapping;

 import org.springframework.web.bind.annotation.RequestMethod;

 import org.springframework.web.bind.support.SessionStatus;

 

 import com.rmigb.bo.Person;

 import com.rmigb.service.PersonService;

 import java.util.List;

 

/*
@Controller
stereotype for presentation layer (spring-mvc)
personcontroller
A Spring Controller, where all requests are mapped
*/

 @Controller

 public class PersonController {

     

/*
personcontroller
Autowiring PersonService
*/

     @Autowired

     PersonService service;

     

/*
Mapping '/add'
When user goto url http://localhost:8080/add, this code executes
*/

     @RequestMapping(value = "/add"method = RequestMethod.GET)

     public String add(Model model) {

         model.addAttribute("person"new Person());

         return "addperson";

     }

     

/*
Mapping '/save'
When user fill up entry form and submit data on server, this code executes
*/

     @RequestMapping(value = "/save"method = RequestMethod.POST)

     public String save(@ModelAttribute("person"Person person,

             BindingResult br,  Model model) {

         if (br.hasErrors()) {

             return "addperson";

         }

         if (person.getId() 0) {

             service.updatePerson(person);

         else {

             service.addPerson(person);

         }

         return "redirect:list";

     }

     

/*
Mapping '/list'
When user goto url http://localhost:8080/list, this code executes
*/

     @RequestMapping(value = "/list"method = RequestMethod.GET)

     public String list(Model model) {

         List<Person> personlist = service.listPerson();

         model.addAttribute("personlist"personlist);

         return "listperson";

     }

     

/*
Mapping '/edit/{id}'
When user goto url http://localhost:8080/edit/{id}, this code executes
*/

     @RequestMapping(value = "/edit/{id}"method = RequestMethod.GET)

     public String edit(@PathVariable Integer idModel model) {

         model.addAttribute("person"service.getPerson(id));

         return "addperson";

     }

     

/*
Mapping '/delete/{id}'
When user goto url http://localhost:8080/delete/{id}, this code executes
*/

     @RequestMapping(value = "/delete/{id}"method = RequestMethod.GET)

     public String delete(@PathVariable Integer id) {

         service.deletePerson(id);

         return "redirect:/list";

     }

 }

 package com.rmigb.bo;

 

 import javax.persistence.Column;

 import javax.persistence.Entity;

 import javax.persistence.GeneratedValue;

 import javax.persistence.GenerationType;

 import javax.persistence.Id;

 import javax.persistence.Table;

 

/*
@Entity
The @Entity annotation is used to mark this class as an Entity bean. So the class should atleast have a package scope no-argument constructor.
person
A Model, which is used to send/retrieve data from/to controller/view
*/

 @Entity

 @Table(name = "person")

 public class Person {

 

     @Id

     @GeneratedValue(strategy = GenerationType.IDENTITY)

     @Column(unique = truenullable = false)

     private int id;

     @Column

     String fname;

     @Column

     String lname;

     @Column

     int age;

     @Column

     float salary;

 

     public int getId() {

         return id;

     }

 

     public void setId(int id) {

         this.id = id;

     }

 

     public String getFname() {

         return fname;

     }

 

     public void setFname(String fname) {

         this.fname = fname;

     }

 

     public String getLname() {

         return lname;

     }

 

     public void setLname(String lname) {

         this.lname = lname;

     }

 

     public int getAge() {

         return age;

     }

 

     public void setAge(int age) {

         this.age = age;

     }

 

     public float getSalary() {

         return salary;

     }

 

     public void setSalary(float salary) {

         this.salary = salary;

     }

 

     @Override

     public String toString() {

         return "Id: " id "; fname : " fname "' age : " age "; Salary: " salary;

     }

 }

 package com.rmigb.dao;

 

 import java.util.List;

 import org.springframework.stereotype.Repository;

 import com.rmigb.bo.Person;

 

 public interface Persondao {

   public Person getPerson(int id);

 

   public List<Person> listPersons();

 

   public void deletePerson(int id);

 

   public void addPerson(Person person);

 

   public void updatePerson(Person person);

 

 }

 package com.rmigb.dao;

 

 import java.util.List;

 

 import org.hibernate.Session;

 import org.hibernate.SessionFactory;

 import org.springframework.beans.factory.annotation.Autowired;

 import org.springframework.stereotype.Component;

 import org.springframework.stereotype.Repository;

 import com.rmigb.bo.Person;

 

/*
@Repository
@Repository annotation is a marker for any class that fulfills the role or stereotype (also known as Data Access Object or DAO) of a repository.
PersondaoImpl
A Repository class with get, add, update, delete and list person
*/

 @Repository

 public class PersondaoImpl implements Persondao {

 

/*
Autowiring SessionFactory
AutoWiring SessionFactory to communicate with database

What is a SessionFactory?
SessionFactory is responsible for the creation of Session instances.
Usually an application has a single SessionFactoryInstance and all threads obtains session instance from this factory.

What is a Session?
A Session works as an intermediate between your application and database.
The main function of the session is to offer create, read, delete operations for instances of mapped entity classes.
*/

   @Autowired

   private SessionFactory sessionFactory;

 

   public Session getCurrentSession() {

     return sessionFactory.getCurrentSession();

   }

 

   @Override

   public Person getPerson(int id) {

     Person person (PersongetCurrentSession().get(Person.classid);

     return person;

   }

 

   @Override

   public List<Person> listPersons() {

     return getCurrentSession().createQuery("From Person").list();

   }

 

   @Override

   public void deletePerson(int id) {

     Person person getPerson(id);

     getCurrentSession().delete(person);

   }

 

   @Override

   public void addPerson(Person person) {

     getCurrentSession().save(person);

 

   }

 

   @Override

   public void updatePerson(Person person) {

     getCurrentSession().update(person);

 

   }

 }

 package com.rmigb.service;

 

 import java.util.List;

 import com.rmigb.bo.Person;

 

 public interface PersonService {

   public Person getPerson(int id);

 

   public void updatePerson(Person person);

 

   public List<Person> listPerson();

 

   public void deletePerson(int id);

 

   public void addPerson(Person person);

 

 }

 package com.rmigb.service;

 

 import java.util.List;

 

 import org.springframework.beans.factory.annotation.Autowired;

 import org.springframework.stereotype.Component;

 import org.springframework.stereotype.Service;

 import org.springframework.transaction.annotation.Transactional;

 

 import com.rmigb.bo.Person;

 import com.rmigb.dao.Persondao;

 

/*
@Service
stereotype for service layer
personserviceimpl
A Service class with get, add, update, delete and list person
*/

 @Service

 @Transactional

 public class PersonServiceImpl implements PersonService {

 

/*
Autowiring
AutoWiring Persondao to access repository class to save/update/retrieve/delete data on databases
*/

   @Autowired

   Persondao personDao;

 

   @Override

   public Person getPerson(int id) {

     return personDao.getPerson(id);

   }

 

   @Override

   public void updatePerson(Person person) {

     personDao.updatePerson(person);

   }

 

   @Override

   public List<Person> listPerson() {

     return personDao.listPersons();

   }

 

   @Override

   public void deletePerson(int id) {

     personDao.deletePerson(id);

 

   }

 

   @Override

   public void addPerson(Person person) {

     personDao.addPerson(person);

 

   }

 

 }

/*
listperson.jsp
A view to display all persons record in list format
*/

 <%taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

 <%taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>

 <%taglib uri="http://www.springframework.org/tags" prefix="s"%>

 <%taglib uri="http://www.springframework.org/tags/form" prefix="form"%>

 <%page session="false"%>

 <html>

     <head>

         <title>Test</title>

     </head>

     <body>

         <a href="${pageContext.request.contextPath}/add">Click here to add new record</a>

         <h1>All Records</h1>

         <div>

             <c:choose>

                 <c:when test="${fn:length(personlist)>0}">

                     <table id="records">

                         <thead>

                             <tr>

                                 <th>Edit</th>

                                 <th>Delete</th>

                                 <th>First Name</th>

                                 <th>Last Name</th>

                                 <th>Age</th>

                                 <th>Salary</th>

                             </tr>

 

 

                             <c:forEach items="${personlist}" var="p">

                                 <tr>

                                     <td><a href="<c:url value="/edit/${p.id}"/>">EDIT</a></td>

                                     <td><a href="<c:url value="/delete/${p.id}"/>">DELETE</a></td>

                                     <td><c:out value="${p.fname}"></c:out></td>

                                     <td><c:out value="${p.lname}"></c:out></td>

                                     <td><c:out value="${p.age}"></c:out></td>

                                     <td><c:out value="${p.salary}"></c:out></td>

                                     </tr>

                             </c:forEach>

                         </thead>

                     </table>

                 </c:when>

                 <c:otherwise>

                     <label>Sorry! No Record To Display</label>

                 </c:otherwise>

             </c:choose>

         </div>

 

 

     </body>

 </html>

/*
addperson.jsp
A view with textboxes, where user can enter and submit data
*/

 <%taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

 <%taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>

 <%taglib uri="http://www.springframework.org/tags" prefix="s"%>

 <%taglib uri="http://www.springframework.org/tags/form" prefix="form"%>

 <%page session="false"%>

 <html>

 <head>

 <title>Add/Edit Record</title>

 </head>

 <body>

   <form:form commandName="person" action="/save" method="post">

     <table>

       <tr>

         <td><label>First Name : </label></td>

         <td><form:hidden path="id" /> <form:input path="fname" /></td>

       </tr>

       <tr>

         <td><label>Last Name : </label></td>

         <td><form:input path="lname" /></td>

       </tr>

       <tr>

         <td><label>Age: </label></td>

         <td><form:input path="age" /></td>

       </tr>

       <tr>

         <td><label>Salary: </label></td>

         <td><form:input path="salary" /></td>

       </tr>

       <tr>

         <td colspan="2"><input type="submit" value="Save"></input></td>

       </tr>

     </table>

   </form:form>

   

 </body>

 </html>

/*
root-context.xml
It is generally used to contain beans that are shared between all servlets in a webapp. We have just one servlet in our application, that is DispatcherServlet . so we dont need to declare any bean here.we will declare all required beans in servlet-context.xml file. So for our this application, this file is unnecessary.
*/

 <?xml version="1.0" encoding="UTF-8"?>

 <beans xmlns="http://www.springframework.org/schema/beans"

   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

   

   <!-- Root Context: defines shared resources visible to all other web components -->

     

 </beans>

/*
servlet-context.xml
The servlet-context.xml defines the beans for one servlet's app context. we can have more than one this kind of configuration files in single application.
for this application, all Spring MVC configuration detail is defined in this file.
*/

 <?xml version="1.0" encoding="UTF-8"?>

 <beans:beans xmlns="http://www.springframework.org/schema/mvc"

   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"

   xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"

   xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd

     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd

     http://www.springframework.org/schema/tx

         http://www.springframework.org/schema/tx/spring-tx.xsd

     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

 

/*
<annotation-driven />
we know we use @controller, @RequestMapping and other annotations in our Spring MVC application. all these annotations have different purposes. <annotation-driven/> is just used to enable these annotations in our application.
In short, we have to write this code in configuration file, if we want to use annotations in our application
*/

   <annotation-driven />

 

/*
<resources>
it is used to specify all static contents's location in our web application, for example, we can set here path for js, css.
But in our application, we are not using any static resource So we can remove this line.
*/

   <resources mapping="/resources/**" location="/resources/" />

/*
View Resolver
After execution, controller returns a logical name, InternalResourceViewResolver add prefix and suffix to that name and provide a view for a particular request.
for example, if controller's method returns hello, then view will be '/WEB-INF/views/hello.jsp' and this view will be rendered and output displayed on browser's screen.
*/

   <beans:bean

     class="org.springframework.web.servlet.view.InternalResourceViewResolver">

     <beans:property name="prefix" value="/WEB-INF/views/" />

     <beans:property name="suffix" value=".jsp" />

   </beans:bean>

 

/*
component-scan
Here we mention those classes' path, in which we are using @Controller, @Repository, @service, @component annotations. and so that it can scan and registers those beans with application context
*/

   <context:component-scan base-package="com.rmigb" />

 

/*
dataSource
We are creating a datasource here and setting properties like driverClassName,url, username,password.
we will use this datasource bean's reference in sessionFactory's dataSource property
*/

   <beans:bean id="dataSource"

     class="org.springframework.jdbc.datasource.DriverManagerDataSource">

     <beans:property name="driverClassName" value="com.mysql.jdbc.Driver" />

     <beans:property name="url" value="jdbc:mysql://localhost:3306/test" />

     <beans:property name="username" value="root" />

     <beans:property name="password" value="" />

   </beans:bean>

 

/*
sessionFactory
Creating a bean sessionFactory of type 'org.springframework.orm.hibernate4.LocalSessionFactoryBean'. Here we are setting dataSource, packageToScan(for entity classes),hibernateProperties etc.. We are going to use this bean's reference in PersondaoImpl class

What is a SessionFactory?
SessionFactory is responsible for the creation of Session instances.
Usually an application has a single SessionFactoryInstance and all threads obtains session instance from this factory.

What is a Session?
A Session works as an intermediate between your application and database.
The main function of the session is to offer create, read, delete operations for instances of mapped entity classes.
*/

   <beans:bean id="sessionFactory"

     class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">

     <beans:property name="dataSource">

       <beans:ref bean="dataSource" />

     </beans:property>

     <beans:property name="packagesToScan" value="com.rmigb.bo">

     </beans:property>

     <beans:property name="hibernateProperties">

       <beans:props>

         <beans:prop key="hibernate.hbm2ddl.auto">

           update

         </beans:prop>

         <beans:prop key="hibernate.show_sql">

           true

         </beans:prop>

         <beans:prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect

         </beans:prop>

       </beans:props>

     </beans:property>

   </beans:bean>

 

 

/*
transactionManager
It Handle transaction management for Hibernate related transactions. Takes care of begin, commit, rollback database transactions.For transactionManagement, we use DataSourceTransactionManager for JDBC, HibernateTransactionManager for Hibernate, JpaTransactionManager for JPA.
*/

   <beans:bean id="transactionManager"

     class="org.springframework.orm.hibernate4.HibernateTransactionManager">

     <beans:property name="sessionFactory">

       <beans:ref bean="sessionFactory" />

     </beans:property>

   </beans:bean>

 

/*
tx:annotation-driven
It scans all beans in the application context and creates AOP interceptor for those which are annotated with @Transactional. Then whenever these beans are accessed, this advice is triggered and a transaction is started before the target method is executed, and committed after the execution.
*/

   <tx:annotation-driven transaction-manager="transactionManager" />

 

 </beans:beans>

/*
web.xml
A web application's deployment descriptor describes the classes, resources and configuration of the application and how the web server uses them to serve web requests. When the web server receives a request for the application, it uses the deployment descriptor to map the URL of the request to the code that ought to handle the request.

for more details :
http://en.wikipedia.org/wiki/Deployment_descriptor
*/

 <?xml version="1.0" encoding="UTF-8"?>

 <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"

   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

 

   <!-- The definition of the Root Spring Container shared by all Servlets and Filters -->

/*
<context-param>
Here we specify location of root-context.xml file, A configuration file which is shared by all servlets and filters.
*/

   <context-param>

     <param-name>contextConfigLocation</param-name>

     <param-value>/WEB-INF/spring/root-context.xml</param-value>

   </context-param>

   

   <!-- Creates the Spring Container shared by all Servlets and Filters -->

/*
<listener>
ContextLoaderListener

As we know, we define our configuration detail in root-context.xml.ContextLoaderListener loads this configuration detail on startup and save it as context so we can use that configuration anywhere in application.
*/

   <listener>

     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

   </listener>

 

   <!-- Processes application requests -->

/*
DispatcherServlet
DispatcherServlet is used to handle incoming request's and searches the handler according to request's url and then move the client request to that handler.
Here We are also specifying location of servlet-context.xml configuration file.
this xml file contains all configuration for spring MVC for example: our controllers, converters, viewresolvers etc.
*/

   <servlet>

     <servlet-name>appServlet</servlet-name>

     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

     <init-param>

       <param-name>contextConfigLocation</param-name>

       <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>

     </init-param>

     <load-on-startup>1</load-on-startup>

   </servlet>

     

/*
<servlet-mapping>
<url-pattern>/</url-pattern> means, all incoming requests are handled by appServlet(defined above)
*/

   <servlet-mapping>

     <servlet-name>appServlet</servlet-name>

     <url-pattern>/</url-pattern>

   </servlet-mapping>

 

 </web-app>

/*
First of all, we are going to see the structure of this project.
Lets first start with pom.xml.

pom.xml
It contains information about the project and configuration details used by Maven to build the project.
for more details :
http://maven.apache.org/guides/introduction/introduction-to-the-pom.html#What_is_a_POM
*/

 <?xml version="1.0" encoding="UTF-8"?>

 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

   <modelVersion>4.0.0</modelVersion>

   <groupId>com.mycompany</groupId>

   <artifactId>rohit</artifactId>

   <name>mynetbeansproject</name>

   <packaging>war</packaging>

   <version>1.0.0-BUILD-SNAPSHOT</version>

   <properties>

     <java-version>1.6</java-version>

     <org.springframework-version>3.1.1.RELEASE</org.springframework-version>

     <org.aspectj-version>1.6.10</org.aspectj-version>

     <org.slf4j-version>1.6.6</org.slf4j-version>

   </properties>

   <dependencies>

     <!-- Spring -->

     <dependency>

       <groupId>org.springframework</groupId>

       <artifactId>spring-context</artifactId>

       <version>${org.springframework-version}</version>

       <exclusions>

         <!-- Exclude Commons Logging in favor of SLF4j -->

         <exclusion>

           <groupId>commons-logging</groupId>

           <artifactId>commons-logging</artifactId>

          </exclusion>

       </exclusions>

     </dependency>

     <dependency>

       <groupId>org.springframework</groupId>

       <artifactId>spring-webmvc</artifactId>

       <version>${org.springframework-version}</version>

     </dependency>

         

     <!-- AspectJ -->

     <dependency>

       <groupId>org.aspectj</groupId>

       <artifactId>aspectjrt</artifactId>

       <version>${org.aspectj-version}</version>

     </dependency>  

     

     <!-- Logging -->

     <dependency>

       <groupId>org.slf4j</groupId>

       <artifactId>slf4j-api</artifactId>

       <version>${org.slf4j-version}</version>

     </dependency>

     <dependency>

       <groupId>org.slf4j</groupId>

       <artifactId>jcl-over-slf4j</artifactId>

       <version>${org.slf4j-version}</version>

       <scope>runtime</scope>

     </dependency>

     <dependency>

       <groupId>org.slf4j</groupId>

       <artifactId>slf4j-log4j12</artifactId>

       <version>${org.slf4j-version}</version>

       <scope>runtime</scope>

     </dependency>

     <dependency>

       <groupId>log4j</groupId>

       <artifactId>log4j</artifactId>

       <version>1.2.15</version>

       <exclusions>

         <exclusion>

           <groupId>javax.mail</groupId>

           <artifactId>mail</artifactId>

         </exclusion>

         <exclusion>

           <groupId>javax.jms</groupId>

           <artifactId>jms</artifactId>

         </exclusion>

         <exclusion>

           <groupId>com.sun.jdmk</groupId>

           <artifactId>jmxtools</artifactId>

         </exclusion>

         <exclusion>

           <groupId>com.sun.jmx</groupId>

           <artifactId>jmxri</artifactId>

         </exclusion>

       </exclusions>

       <scope>runtime</scope>

     </dependency>

 

     <!-- @@Inject -->

     <dependency>

       <groupId>javax.inject</groupId>

       <artifactId>javax.inject</artifactId>

       <version>1</version>

     </dependency>

         

     <!-- Servlet -->

     <dependency>

       <groupId>javax.servlet</groupId>

       <artifactId>servlet-api</artifactId>

       <version>2.5</version>

       <scope>provided</scope>

     </dependency>

     <dependency>

       <groupId>javax.servlet.jsp</groupId>

       <artifactId>jsp-api</artifactId>

       <version>2.1</version>

       <scope>provided</scope>

     </dependency>

     <dependency>

       <groupId>javax.servlet</groupId>

       <artifactId>jstl</artifactId>

       <version>1.2</version>

     </dependency>

   

     <!-- Test -->

     <dependency>

       <groupId>junit</groupId>

       <artifactId>junit</artifactId>

       <version>4.7</version>

       <scope>test</scope>

     </dependency>        

   </dependencies>

     <build>

         <plugins>

             <plugin>

                 <artifactId>maven-eclipse-plugin</artifactId>

                 <version>2.9</version>

                 <configuration>

                     <additionalProjectnatures>

                         <projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>

                     </additionalProjectnatures>

                     <additionalBuildcommands>

                         <buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>

                     </additionalBuildcommands>

                     <downloadSources>true</downloadSources>

                     <downloadJavadocs>true</downloadJavadocs>

                 </configuration>

             </plugin>

             <plugin>

                 <groupId>org.apache.maven.plugins</groupId>

                 <artifactId>maven-compiler-plugin</artifactId>

                 <version>2.5.1</version>

                 <configuration>

                     <source>1.6</source>

                     <target>1.6</target>

                     <compilerArgument>-Xlint:all</compilerArgument>

                     <showWarnings>true</showWarnings>

                     <showDeprecation>true</showDeprecation>

                 </configuration>

             </plugin>

             <plugin>

                 <groupId>org.codehaus.mojo</groupId>

                 <artifactId>exec-maven-plugin</artifactId>

                 <version>1.2.1</version>

                 <configuration>

                     <mainClass>org.test.int1.Main</mainClass>

                 </configuration>

             </plugin>

         </plugins>

     </build>

 </project>

  • (1) Stop Learning Small tutorials. Just Start To Develop a Project and Learn By Writing code.
  • (2) We will help you from startup till the completion of large project.
  • (3) You can ask us any question any time through skype.
  • (4) You will get 3 online demo classes.
  • (5) You will work on shopping project with one of our team member.
  • (6) We will charge only 4$/month or 200 rs(INR)
  • What benefit you will get
  • (1) You will save more than 300 hrs.
  • (2) With Self Study, You can learn only few topics, We will teach everything about Spring MVC and Spring Security (more than 250 topics).
  • our skype id :programsji
  • our mail id :programsjiseo@gmail.com

Comments

VARIABLES INFO

OUTPUT ON CONSOLE

PRESS DOWN ARROW

 Once There

 

 Was A

 Rohit Malhotra

 He Was Very

 Good boy

 Once There

 

 Was A

 Rohit Malhotra

 He Was Very

 Good boy

 Once There

 

 Was A

 Rohit Malhotra

 He Was Very

 Good boy

We have three ways to learn this code