Spring mvc interview

·

2 min read

. What is MVC

MVC is a design pattern. M for model, V for view and C for controller

. What are the components for

. Model contains the business logic and data access. The realisation of model using the ORM based frameworks hibernate, spring jpa and data model itself DTO, Pojo objects.

. View contains no logic. It is responsible for the representation of data in different formats. Various technologies jsp, xslt, javaScript based framework angular.js ect.

. Controller receives the request and performs the interactions on the data model. Implementation of a rest controller using spring web.

. What are the advantages of MVC

. decoupling

Decoupling of the task from frontend and backend. Once the model has been implemented, the frontend developer can mock the data and start to build the UI, the decoupling accelerates the speed of developing the web application and improves the testability

. reusable business code

In order to extend a particular framework, the existing model can be reused

Example:

Model : Survey

A survey consists of multiple questions. One question containing multiple ways of answering it, to represent a matrix it requires subanswers to an answer.

View will be modified for an answer by changing the type. Assume that type a is single choice, b is multi choice, c is matrix and d is plaintext.

Now for the same description of a question :

Which language do you speak?

Controller: there are a lots of tutorials about how to implement a Restcontroller by using the spring framework.