发布时间:2023-02-13 14:30
具体的坐标如下:
<properties>
<spring.version>5.0.2.RELEASEspring.version>
properties>
<dependencies>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-contextartifactId>
<version>${spring.version}version>
dependency>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-webartifactId>
<version>${spring.version}version>
dependency>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-webmvcartifactId>
<version>${spring.version}version>
dependency>
<dependency>
<groupId>javax.servletgroupId>
<artifactId>servlet-apiartifactId>
<version>2.5version>
<scope>providedscope>
dependency>
<dependency>
<groupId>javax.servlet.jspgroupId>
<artifactId>jsp-apiartifactId>
<version>2.0version>
<scope>providedscope>
dependency>
dependencies>
在web.xml配置文件中核心控制器DispatcherServlet
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<servlet>
<servlet-name>SpringMVCDispatcherServletservlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
servlet-class>
<init-param>
<param-name>contextConfigLocationparam-name>
<param-value>classpath:SpringMVC.xmlparam-value>
init-param>
<load-on-startup>1load-on-startup>
servlet>
<servlet-mapping>
<servlet-name>SpringMVCDispatcherServletservlet-name>
<url-pattern>/url-pattern>
servlet-mapping>
创建 spring mvc 的配置文件
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="com.itheima">context:component-scan>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/pages/">property>
<property name="suffix" value=".jsp">property>
bean>
beans>
编写控制器并使用注解配置
@Controller("helloController")
public class HelloController {
@RequestMapping("/hello")
public String sayHello() {
System.out.println("HelloController 的 sayHello 方法执行了。。。。 ");
return "success";
}
}
测试
案例的执行过程
1、服务器启动,应用被加载。 读取到 web.xml 中的配置创建 spring 容器并且初始化容器中的对象。
MindSpore报错 Select GPU kernel op * fail! Incompatible data type
React + Node.js 全栈实战教程 - 手把手教你搭建「文件上传」管理后台
(附源码)多种机器学习模型(KNN\LR\RF\Ada\Xg\GBDT...)下的降水降尺度中的模型训练
官宣|九章云极DataCanvas核心产品通过 “可信大数据”权威评测
【YOLOV5-6.x中文注释版】整体项目代码全中文注释导航页面-By2022
一个接口优雅的实现 Spring Cloud OAuth2 自定义token返回格式
Jetson 学习笔记(十二):CSI摄像头实现rtsp流的传输并对动态获取多路流进行探索