-
视图(View)-对应组件:JSP或者HTML文件
-
控制器(Controller)-对应组件:Servlet
-
模型(Model) -对应组件:JavaBean
三层:表示层、业务逻辑层、数据访问层
MVC与三层:
表示层:V C
业务逻辑层、数据访问层 : M
MVC 优点-
MVC 优点
-
多视图共享一个模型,大大提高代码的可重用性
-
MVC三个模块相互独立,松耦合架构
-
控制器提高了应用程序的灵活性和可配置性
-
有利于软件工程化管理
-
完美的系统架构 = 松耦合+高重用性+高扩展性
-
-
-
MVC 缺点
-
原理复杂
-
增加了系统结构和实现的复杂性
-
视图对模型数据的低效率访问
-
-
结构最清晰的MVC Model2实现
-
Controller
-
ModelAndView
在web.xml中配置DispatcherServlet 5.3.6 org.springframework spring-webmvc${spring.version}
Spring MVC的配置文件springMVC org.springframework.web.servlet.DispatcherServlet contextConfigLocation classpath:springmvc.xml 1 springMVC /
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("/")
public class HelloController {
@RequestMapping("/hello")
public String hello(){
return "hello";
}
}
创建View-JSP
创建在WEB-INF/jsp/hello.jsp
hello spring mvc



