SpringMVC学习笔记(一、环境搭建)

xiaoxiao2025-11-07  5

SpringMVC主要功能

在获取多个参数、文件上传、servlet功能单一方面都有很好的解决办法

SpringMVC 环境搭建

构建一个空的WEB项目(记住勾选xml文件)导入所需jar包 书写主配置文件: 创建resource文件夹 创建springmvc.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd "> </beans >

在web.xml中添加以下代码

<!-- 配置SpringMVC的核心控制器类:DispatcherServlet --> <servlet> <servlet-name>dispatcherServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:springmvc.xml</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>dispatcherServlet</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> </web-app>

在springmvc.xml中添加controller层包扫描

<!-- 配置包扫描 --> <context:component-scan base-package="cn.java.controller"></context:component-scan>

在springmvc.xml中添加注解驱动

<!-- 加入SpringMVC特有的注解驱动 --> <mvc:annotation-driven></mvc:annotation-driven>
转载请注明原文地址: https://www.6miu.com/read-5039228.html

最新回复(0)