SpringMVC简介
1.导入spring-mvc坐标
<dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><version>5.3.7</version></dependency>
2.在web.xml里配置DispatcherServlet前端控制器
<!-- 配置DispatcherServlet前端控制器--><servlet><servlet-name>DispatcherServlet</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><param-name>contextConfigLocationn</param-name><param-value>classpath:spring-mvc.xml</param-value></init-param><load-on-startup>2</load-on-startup></servlet>
3.编写controller(注入了spring容器里的servise)
@Controller
public class QuickController {//直接注入service进行使用@Autowiredprivate QuickService quickService;@RequestMapping("/show")public String show(){System.out.println("show running..."+quickService);return "/index.jsp";}}
3.5 spring-mvc容器组件扫描
<!-- 组件扫描--><context:component-scan base-package="com.itheima.controller"/>
3.5.5 返回页面index.jsp
<%--Created by IntelliJ IDEA.User: haohaoDate: 2022/12/1Time: 16:04To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head><title>Title</title>
</head>
<body><h1>Hello SpringMVC!</h1></body>
</html>
spring容器仍然为:service+application.xml模式