Spring MVC Hibernate MySQL – Multiple Controllers

Spring MVC Hibernate MySQL – Multiple Controllers:
In our previous example we implemented Spring MVC Hibernate MySQL CRUD Operations (Here). In this article we are going to see how to use Multiple Controllers using Spring MVC.

In the below example, We are going to create 2 entities Employee and Manager and will have separate controllers for both these entities. Let us see how to add, view and delete. Edit operation is same as we discussed in previous example (Here), So i have not implemented Edit operation in this example.

Project Structure:

POM.xml

com.javainfinite.model:
Employee.java

Manager.java

com.javainfinite.dao:
EmployeeDAO.java

ManagerDAO.java

EmployeeDAOImpl.java

ManagerDAOImpl.java

com.javainfinite.service
EmployeeService.java

ManagerService.java

EmployeeServiceImpl.java

ManagerServiceImpl.java

spring-config.xml

web.xml

employee.jsp

manager.jsp

Output:

After Adding,

Deleting Employee,

On Clicking Manager Link,

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Read More

Spring MVC Hibernate MySQL CRUD Operation

Spring MVC Hibernate MySQL CRUD Operation:
The idea of MVC framework is to separate the business logic from front end and change them without affecting others.

Model: Represents data
View: User Interface of the application
Controller: Receives request and perform the operations

 

  • The request is received by the dispatcher servlet
  • The dispatcher Servlet checks with the Handler Mappings to determine the appropriate controller to pass the request
  • The dispatcher Servlet get the appropriate controller from Handler Mapping and passes the request to Controller.
  • The controller sends the request along with the object containing the name of the view and data to be displayed, but not the exact logical name
  • Dispatcher Servlet after receiving the name, checks with view resolver to resolve the actual logical name.
  • Finally the view is displayed to the user

Now let us see the example of Spring MVC, Hibernate with MySQL.

Project Structure:

pom.xml

Employee.java

EmployeeDAO

EmployeeDAOImpl.java

EmployeeService

EmployeeServiceImpl

EmployeeController.java

 

spring-config.xml

web.xml

employee.jsp

edit.jsp

Output:

On clicking Edit

 

Create Another record,

Deleting Alpha record,

 

 

 

 

Read More