EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login
Home Software Development Software Development Tutorials Spring Tutorial Spring Boot MVC
Secondary Sidebar
Spring Tutorial
  • Spring Boot
    • What is Spring Boot
    • Spring Boot flyway
    • Spring Boot framework
    • Spring Boot Logback
    • Spring Boot actuator endpoints
    • Spring Boot gRPC
    • Spring Boot jdbctemplate example
    • Spring Boot ehcache
    • Spring Boot Architecture
    • Spring Boot Port
    • Introduction of spring boot
    • Spring Boot ide
    • Spring Boot Netty
    • Spring Boot ORM
    • Spring Boot Versions
    • Spring Boot JUnit
    • Spring Boot Keycloak
    • Spring Boot gradle
    • Spring Boot Lombok
    • Spring Boot autowired
    • Spring Boot bean
    • Spring Boot hibernate
    • Spring Boot integration test
    • Spring Boot jdbc
    • Spring Boot MongoDB
    • Spring Boot postgresql
    • Spring Boot rest
    • Spring Boot swagger
    • Spring Boot thymeleaf
    • Spring Boot Unit Test
    • Spring Boot Webflux
    • Spring Boot webclient
    • Spring Boot kubernetes
    • Spring Boot Properties
    • Spring Boot Validation
    • Spring Boot Feature
    • Spring Boot Application
    • Spring Boot email
    • Spring Boot MVC
    • Spring Boot Exception Handling
    • Spring Boot Starter Parent
    • Spring Boot Docker
    • Spring Boot Logging
    • Spring Boot Query
    • Spring Boot Multiple Data Sources
    • Spring Boot Basic Authentication
    • Spring Boot Test
    • Spring Boot jwt
    • Spring Boot Liquibase
    • Spring Boot Prometheus
    • Spring Boot debug
    • Spring Boot GraalVM
    • Spring Boot Batch
    • Spring Boot controller
    • Spring Boot CLI
    • Spring Boot file upload
    • Spring Boot interceptor
    • Spring Boot Service
    • Spring Boot Configuration
    • Spring Boot Datasource Configuration
    • Spring Boot Annotations
    • Spring Boot Starter We
    • Spring Boot Actuator
    • Spring Boot DevTools
    • Spring Boot Repository
    • Spring Boot Dependencies
    • Spring Boot Path Variable
    • Spring Boot Microservices
    • Spring Boot Run Command
    • Spring Boot application.properties
    • Spring Boot Transaction Management
    • Spring Boot Banner
    • Spring Boot JPA
    • Spring Boot Change Port
    • Spring Boot RestTemplate
    • Spring Boot cors
    • Spring Boot HTTPS
    • Spring Boot OAuth2
    • Spring Boot Profiles
    • Spring Boot Interview Questions
    • Spring Boot filter
    • Spring boot logging level
    • Spring Boot Cache
    • Spring Boot Advantages
    • Spring Boot Scheduler
    • Spring Boot Initializr
    • Spring Boot Maven
    • Spring Boot Admin
    • Spring Boot Tomcat
    • Spring Boot WebSocket
    • Spring Boot Executable Jar
    • Spring Boot CommandLineRunner
    • Spring Boot DataSource
    • Spring boot grpc
    • Spring Batch Scheduler
    • Spring Batch Example
    • Spring Batch Tasklet
    • Spring Batch Admin
    • Spring Batch
    • Spring Boot Qualifier
    • Spring Boot War
    • Spring Boot Test Configuration
  • Spring
    • What is Spring Framework?
    • Spring Architecture
    • What is Spring Integration?
    • IoC Containers
    • What is AOP?
    • Spring Modules
    • Spring Batch Processing
    • Spring Batch Partitioner
    • Spring Batch Job
    • Spring AOP
    • Spring Expression Language
    • Dependency Injection in Spring
    • Spring Batch Architecture
    • Spring framework Interview Questions
  • Spring Cloud Basics
    • What is Spring Cloud
    • Spring Cloud Contract
    • Spring Cloud Components
    • Spring Cloud Version
    • Spring Cloud Data Flow
    • Spring cloud stream
    • Spring Cloud Dependencies
    • Spring cloud microservices
    • spring cloud gateway
    • Spring Cloud Config
    • Spring Cloud Kubernetes
    • Spring Cloud Sleuth

Related Courses

Spring Boot Certification Course

Spring Framework Course Training

All in One Data Science Course

Spring Boot MVC

Spring Boot MVC

Introduction to Spring Boot MVC

Spring Boot MVC is a module of the spring framework which was dealing with the MVC pattern or model view controller, it will combine all the advantages from the MVC pattern which was spring boot convenience. Spring boot will implement the MVC with a pattern of the front controller by using the servlet dispatcher. In nutshell, the servlet dispatcher will act as the main controller which was routing the request from their intended destination. Spring boot model is nothing but the application data and view which was represented by various engines of templates. We can use spring boot MVC in multiple template engines.

What is Spring Boot MVC?

It is widely used to create scalable web applications. To develop a web application framework is providing the module which was used to create the web application. The model object passes between the controller and view which was using the maps.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

This framework will consist following components as follows:

All in One Software Development Bundle(600+ Courses, 50+ projects)
Python TutorialC SharpJavaJavaScript
C Plus PlusSoftware TestingSQLKali Linux
Price
View Courses
600+ Online Courses | 50+ projects | 3000+ Hours | Verifiable Certificates | Lifetime Access
4.6 (86,130 ratings)
  • Model
  • View
  • Controller
  • Front Controller

1. Model

  • The model is nothing but the object or collection of objects which contained the application data.
  • Model is a very important component while developing applications.

2. View

  • The view component is used to display the user information.
  • This user information using view components will be displayed in a specific format. As we know that spring boot will support multiple technologies like velocity, thymeleaf and free maker.
  • We can display the specific user information by using this component.

3. Controller

  • This component will contain the logical part of our application.
  • We are using @controller annotation to mark our project class as controller.

4. Front Controller

  • This component is responsible to manage the flow of our application. In servlet dispatcher will act as the front controller.

At the time of using spring boot MVC in our project, we need to configure the same manually. We also require the deployment descriptor.

Spring Boot MVC Method

  • It is providing a very elegant solution to use the MVC in the spring boot framework.
  • We are using DispatcherServlet method in the spring boot application. The DispatcherServlet is a class that was used to receive the incoming request from an application, after receiving the incoming requests we have mapped the same with correct resources like view, model, or controllers.
  • We are using the @Controller annotation to make our class a controller.
  • Basically, there are two types of methods we have used at the time of developing the application i.e. get and post.
  • The controller takes the request from DispatcherServlet, after taking the request it will call the appropriate method like GET or POST.
  • The service method will make the data model based on the return view name and the business logic.
  • The DispatcherServlet will take help from the ViewResolver to get the defined view or the request.
  • Once we have finalized the view in the project DispatcherServlet will pass the model data to the view.
  • HandlerMapping, ViewResolver, and the controller are part of our web application context file. This file is an extension of the plain application context.

Getting the Required

To develop an application we need to use the following technologies in our application.

  • Spring boot 2.5.4
  • Spring webmvc 4.3.9
  • Embedded tomcat 8.5
  • Java 8
  • Maven 3.3.9
  • Spring tool suite or eclipse

To develop the application first we need to add the dependency in pom.xml file. After adding the dependency we need to do application configuration in our main class file. After application configuration, we need to configure the application properties for our project. After adding the application properties we need to add the security of our application.

After adding security to our application next step is to define the data model for our application. After defining the data model next step is to set the simple controller of our application. After defining the controller our application is ready to use, we can check and test our application.

Examples

Below example shows to setup spring boot PostgreSQL application as follows:

1. Create a project template using spring initializer and give the following name to the project metadata.

Group – com.example
Artifact name – spring-boot-mvc
Name – spring-boot- mvc
Description – Project of spring-boot- mvc
Package name – com.example.spring-boot- mvc
Packaging – Jar
Java – 11
Dependencies – spring web.

Spring Boot MVC 1

2. After generating the project extract files and open this project by using the spring tool suite.

Spring Boot MVC 2

3. After opening the project using the spring tool suite check the project and its files.

Spring Boot MVC 3

4. Add required dependency in pom.xml file.

Code:

<dependency> -- Start of dependency tag.
<groupId>org.springframework</groupId> -- Start and end of groupId tag.
<artifactId>spring-webmvc</artifactId> -- Start and end of artifactId tag.
</dependency> -- End of dependency tag.

Output:

Spring Boot MVC 4

5. Create controller class.

Code:

@Controller
public class springmvc {
@RequestMapping("/")
public String display()
{
return "index";
} }

Output:

Spring Boot MVC 5

6. Provide the entry of the controller.

Code:

<servlet> -- Start of servlet tag.
<servlet-name>spring-boot-mvc</servlet-name> -- Start and end of servlet name tag.
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> --start and end of servlet class.
<load-on-startup>1</load-on-startup>
</servlet> -- End of servlet tag.
<servlet-mapping> -- Start of servlet mapping tag.
<servlet-name>spring-boot-mvc</servlet-name> -- Start and end of servlet name tag.
</servlet-mapping>

Output:

Provide the entry of controller

7. Define bean in xml file.

Code:

<context:component-scan base-package="com.myexample" />
<mvc:annotation-driven/>

Output:

Define bean in xml file

8. Display the message.

Code:

<body> -- Start of body tag.
<p>Welcome to Spring MVC Tutorial</p> -- Start and end of p tag.
</body> -- End of body tag.

Output:

Display the message

9 Run the application.

Run the application

10. Check output on web browser.

http://localhost:8080/SpringMVC/

Spring Boot MVC 10

Conclusion

It enables the developer to develop a complex and widely used application that uses simple java classes. The framework will enable the separation modules such as controller, model view, and integration which was seamlessly handled by the application.

Recommended Articles

This is a guide to Spring Boot MVC. Here we discuss the introduction, what is spring boot MVC? method and example respectively. You may also have a look at the following articles to learn more –

  1. Maven Repository Spring
  2. Spring Boot DevTools
  3. Spring AOP
  4. Spring Cloud Components
Popular Course in this category
Spring Boot Training Program (2 Courses, 3 Project)
  2 Online Courses |  3 Hands-on Projects |  22+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course

Related Courses

Spring Framework Training (4 Courses, 6 Projects)4.9
All in One Data Science Bundle (360+ Courses, 50+ projects)4.8
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Software Development Course

C# Programming, Conditional Constructs, Loops, Arrays, OOPS Concept

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

Special Offer - Spring Boot Training Program (2 Courses, 3 Project) Learn More