SpringMVC环境配置

1.maven依赖spring-webmvc

2.web.xml配置DispatcherServlet

3.配置applicationContext.xml的mvc标记

复制代码
<?xml version="1.0" encoding="UTF-8"?>
<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" xmlns:mv="http://www.springframework.org/schema/mvc"
       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">
    <!--
        context:component-scan标签作用
        在Spring IOC 初始化过程中,自动创建并管理com.spring及子包中
        拥有以下注解的对象
        @Repository 通常书写在dao与数据交互的类
        @Service 业务逻辑类,放在xxxService类上
        @Controller 控制器类
        @Component 如果类不好区分类型,就可以使用Component
    -->
    <context:component-scan base-package="com.spring"/>
    <!--启用Spring MVC的注解开发模式-->
    <mvc:annotation-driven/>
    <!--将图片/js/css等静态资源排除在外,可提高执行效率-->
    <mvc:default-servlet-handler/>
</beans>
复制代码

4.开发Controller控制器

 

posted @   南风知君  阅读(115)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
点击右上角即可分享
微信分享提示