Unit4 Teena
Unit4 Teena
Greater Noida
Unit: 4
Ms. Teena
Spring MVC & Spring Boot Assistant Professor
CSE Department
Course Details
(B Tech VI Sem / 3rd Year)
•• Develop
Develop error-free,
error-free,well-documented
well-documentedJava Java programs;
programs; develop
develop andand
test Java
test Javasearch
network, network, search
engine, engine,
and web and web
framework framework
programs. programs.
Learn how to write, test,
Learn how to write, test, and debug advanced-level Object-Oriented
and debug advanced-level
programs using Java. Object-Oriented programs using Java.
• Develop error-free, well-documented Java programs; develop and test Java
• network,
to provide the ability
search engine,toand
design console based,
web framework GUI based
programs. Learn ,web
how tobased
write, test,
applications,
and integratedwell-documented
debug error-free, development environment to create,
Java programs; debug
develop andand
test Java
run multi-tier and enterprise-level application
network, search engine, and web framework programs. Learn how to write, test,
and debug advanced-level Object-Oriented programs using Object-Oriented
programs using Java.
PO3
To demonstrate, understand and use of different concept of
MVC, JDBC, Spring etc.
PO4 To solve the real time problems using using advance concept
of Java.
PO5
To understand the JPA and entities relationship.
PO PO PO PO PO PO PO PO PO PO PO PO
1 2 3 4 5 6 7 8 9 10 11 12
CO.1 3 3 3 2 1 2 3
CO.2 3 3 3 2 1 2 3
CO.3 3 3 3 2 1 2 3
CO.4 3 3 3 2 1 2 3
CO.5 3 3 3 2 1 2 3
CO.2 2 3 2 1
CO.3 2 3 2 1
CO.4 2 3 2 1
CO.5 2 3 2 1
Spring Boot
• Spring Boot Starters
• CLI
• Application Class
• Logging
• Auto Configuration Classes
• Spring Boot Dependencies
• Spring data JPA introduction and Overview
• Model - A model contains the data of the application. A data can be a single object
or a collection of objects. The Model encapsulates the application data and in
general, they will consist of POJO.
• Front Controller - In Spring Web MVC, the DispatcherServlet class works as the front
controller. It is responsible to manage the flow of the Spring MVC application.
17/11/2024 Ms.Teena ACSE0601 Advanced Java Programming 28
Working of MVC Framework
Answer:
c) Model-View-Controller
Explanation:
MVC stands for Model-View-Controller, which is a design pattern to separate an
application's concerns.
Answer:
b) A lightweight Java framework for building web applications.
Explanation:
Spring MVC is a lightweight Java framework built on top of the Spring
Framework. It provides a flexible architecture for developing web applications
based on the Model-View-Controller design pattern. Spring MVC simplifies web
development by providing features such as request handling, view rendering,
and data binding.
Answer:
d) @Controller
Explanation:
The @Controller annotation indicates that a class is a Spring MVC controller.
Answer:
a) Dispatcher Servlet
Explanation:
In Spring MVC, the Dispatcher Servlet is responsible for dispatching incoming
HTTP requests to the appropriate controller methods.
Answer:
a) @Model Attribute
Explanation:
The @Model Attribute annotation is used to bind a method parameter to a
named attribute, potentially initializing the attribute from a database or other
source.
Answer:
a) @Exception Handler
Explanation:
The @Exception Handler annotation is used to handle exceptions in Spring MVC.
7. What is the purpose of the Model And View object in Spring MVC?
a) To store and pass data between the controller and the view.
b) To define the layout and styling of the web application.
c) To handle user authentication and authorization.
d) To manage the application's data access layer.
Answer:
a) To store and pass data between the controller and the view.
Explanation:
The Model And View object in Spring MVC is used to store and pass data
between the controller and the view. It combines both the model and view
aspects, allowing the controller to add data to the model and specify the view
that should be rendered. The Model And View object serves as a container for
carrying data and view information during request processing in Spring MVC.
Answer:
a) @Request Header
Explanation:
The @Request Header annotation is used to bind a method parameter to a
specific web request header.
Answer:
a) By using the @Request Param annotation.
Explanation:
In a Spring MVC controller method, you can access request parameters by using the
@Request Param annotation. This annotation binds a request parameter value to a
method parameter, making it easy to retrieve and process the parameter value in
the controller.
Answer:
c) Resolving views to specific URLs
Explanation:
View Resolver in Spring MVC helps in mapping view names to actual views (like
JSPs).
12. Which Spring MVC module provides integration with RESTful services?
a) Spring Rest Controller
b) Spring REST
c) Spring Web MVC
d) Spring Web Flux
Answer:
c) Spring Web MVC
Explanation:
While @Rest Controller is an annotation used to create REST ful controllers, it's the
Spring Web MVC module that provides integration with REST ful services.
13. Which annotation indicates a method should handle HTTP POST requests?
a) @Http Post
b) @Post Handler
c)@Request Mapping (method = Request Method.POST)
d) @Post Mapping
Answer:
d) @Post Mapping
Explanation:
The @Post Mapping is a composed annotation that acts as a shortcut for @Request
Mapping(method = Request Method.POST).
Answer:
a) It sends the return value of a method back to the web response body.
Explanation:
The @Response Body annotation tells a controller that the return value of a
method should be written directly to the HTTP response body.
Answer:
a) "redirect:/url_path"
Explanation:
In Spring MVC, to perform a redirect, you return a string starting with "redirect:"
followed by the path.
Answer:
b) @Multipart File
Explanation:
The @Multipart File annotation is used to handle multipart file uploads in
Spring MVC.
17. How do you specify that a controller method should produce JSON as a
response?
a) @Produces("application/json")
b) @ResponseBody(type="json")
c) @ResponseFormat("JSON")
d) @RequestMapping(produces="application/json")
Answer:
d) @RequestMapping(produces="application/json")
Explanation:
The @RequestMapping annotation with the produces attribute set to
"application/json" specifies that the controller method should produce JSON as a
response.
Answer:
c) @ModelAttribute
Explanation:
@ModelAttribute can be used to represent a form-backing bean in Spring
MVC.
Answer:
c) Handler Mapping
Explanation:
The Handler Mapping component decides which controller method should be
called based on the incoming request.
Answer:
b) It triggers validation of a method parameter or field.
Explanation:
The @Valid annotation triggers validation of the annotated method parameter
or field.
Answer:
4. All of the above
Explanation:
Spring boot is used to build Web applications, REST APIs, and
Microservices.
Answer:
1. Web-based tool to bootstrap Spring projects and generate project skeletons with
the necessary configurations and dependencies.
Explanation:
Spring Initializr is a web-based tool provided by the Spring team to bootstrap Spring
projects and generate project skeletons with the necessary configurations and
dependencies. It simplifies the process of creating a new Spring-based application
by providing an intuitive user interface to customize and generate project structures.
Answer:
1. @RestController
Explanation:
When you annotate a class with @RestController, it indicates that the
class is a Spring MVC REST controller responsible for handling incoming
HTTP requests and generating the appropriate HTTP responses.
Answer:
1. @GetMapping
Explanation:
The @GetMapping annotation is used to map an HTTP GET request to
a specific handler method in a Spring MVC controller. It is a shortcut
for specifying the @RequestMapping annotation with the
RequestMethod.GET method.
Answer:
2. @Service
Explanation:
The @Service annotation is used in Spring Framework to mark a class
as a service component. It is typically applied to classes that perform
business logic, transaction management, or other services in an
application.
17/11/2024 Ms.Teena ACSE0601 Advanced Java Programming 80
Daily Quiz - MCQ
Answer:
2. spring-boot-starter-web
Explanation:
The spring-boot-starter-web dependency provides the necessary
components to develop Web Applications and RESTful API in a Spring
Boot project, including the embedded Tomcat server, Spring Web
MVC, and other required dependencies.
17/11/2024 Ms.Teena ACSE0601 Advanced Java Programming 82
Spring Boot Application
Answer:
a) @CrossOrigin
Explanation:
The @CrossOrigin annotation is used in Spring MVC to handle Cross-Origin
Resource Sharing (CORS).
35. Which Spring Boot Starter would you use for developing web applications?
a) spring-boot-starter-web
b) spring-boot-starter-jdbc
c) spring-boot-starter-data
d) spring-boot-starter-app
Answer:
a) spring-boot-starter-web
Explanation:
spring-boot-starter-web is used for building web, including RESTful, applications
using Spring MVC.
Answer:
c) Presentation layer
Explanation:
Spring MVC is used in the presentation layer to handle web requests and construct
responses.
• What is JPA?
• Spring Boot JPA is a Java specification for
managing relational data in Java applications. It allows us to access
and persist data between Java object/ class and relational database.
JPA follows Object-Relation Mapping (ORM). It is a set of
interfaces. It also provides a runtime EntityManager API for
processing queries and transactions on the objects against the
database. It uses a platform-independent object-oriented query
language JPQL (Java Persistent Query Language).
• In the context of persistence, it covers three areas:
• The Java Persistence API
• Object-Relational metadata
• The API itself, defined in the persistence package.
• JPA is not a framework. It defines a concept that can be implemented
by any framework.
17/11/2024 98
Ms.Teena ACSE0601 Advanced Java Programming
JPA Implementations
17/11/2024 99
Ms.Teena ACSE0601 Advanced Java Programming
Daily Quiz - MCQ
4. ____ is a class that allows you to persist, update, and delete entities.
A. Persistence
B. Entity
C. EntityManager
D. Bias
Answer: C) EntityManager
Explanation:
EntityManager is a class that allows you to persist, update, and delete entities.
10. Which of the following annotations is used to indicate an entity's primary key
field?
@pk
@primary
@key
@id
Answer: D) @id
Explanation:
@id annotation is used to specify the primary key field of an entity.
17/11/2024 Ms.Teena ACSE0601 Advanced Java Programming 105
Daily Quiz - MCQ
11. ____ is a programming capability that allows data to be converted from
object type to relational type and vice versa.
A. ORM
B. JPA
C. JRE
D. Java RMI
Answer: A) ORM
Explanation:
ORM is a programming capability that allows data to be converted from object
type to relational type and vice versa.
https://www.vturesource.com/vtu/3704942925/Advanced-JAVA-and-
J2EE/15CS553/Feb-2021
1) What is MVC?
2) What is Spring MVC?
3) What is the front controller of Spring MVC?
4) Explain the flow of Spring MVC?
5) What are the advantages of Spring MVC Framework?