Junior — Middle
Explain the concept of Spring MVC and its role in developing web applications in Java.
sobes.tech AI
Answer from AI
Spring MVC is a framework for building web applications in Java, based on the Model-View-Controller (MVC) pattern. Its goal is to separate the application logic into three parts:
- Model — business logic and data.
- View — user interface, usually HTML or templates.
- Controller — request handling, linking the model and view.
Spring MVC simplifies development by providing convenient annotations for routing HTTP requests, data validation, form processing, and integration with other Spring components. This allows creating scalable and maintainable web applications.
Example of a controller in Spring MVC:
@Controller
public class HelloController {
@GetMapping("/hello")
public String sayHello(Model model) {
model.addAttribute("message", "Hello, Spring MVC!");
return "hello"; // view name
}
}