zoukankan      html  css  js  c++  java
  • ssm框架整合入门系列——配置SpringMVC dispatcherServlet-servlet.xml

    配置SpringMVC


    dispatcherServlet-servlet.xml

    在ssm-crud项目中
    SpringMVC的配置主要是在dispatcherServlet-servlet.xml文件

    在这之前,先修改beans的头信息,否则按alt+/ 快捷键没有提示,并且添加context:component-scan还报错:context:component-scan is not bound,后来找到的解决方法:context:component-scan is not bound

    我试图了解一下这些配置的信息,但是并没有找到比较让人清晰明了的文章,未来如果找到我会放在这里:地址(挖个坑)。

    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:context="http://www.springframework.org/schema/context"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd">  
    </beans>
    

    然后,我们在src/main/java文件夹添加未来我们需要的文件夹:

    • com.liantao.crud.bean
    • com.liantao.crud.controller
    • com.liantao.crud.dao
    • com.liantao.crud.service
    • com.liantao.crud.test
    • com.liantao.crud.utils

    点击xml文件左下角的Namespaces勾选上context,beans,如图:
    namespaces
    namespaces
    接着,dispatcherServlet-servlet.xml文件添加:

    	<!-- SpringMVC的配置文件,包含网站跳转逻辑的控制配置 -->
    	<context:component-scan base-package="com.liantao" use-default-filters="false">
    		<!-- 只扫描控制器 -->
    		<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    	</context:component-scan>
    

    作用:让SpringMVC只扫描com.liantao.crud.controller
    先知道作用就够了,这里有一篇<context:component-scan/>的详细介绍:context:component-scan

    ViewResolver 视图解析器

    <!-- 视图解析器,方便页面返回 -->
    	<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    		<property name="prefix" value="/WEB-INF/views/"></property>
    		<property name="suffix" value=".jsp"></property>
    	</bean>
    

    作用:简单描述就是对Controller类中每个函数返回值那里的String类型前后加路径
    关于它的分析:ViewResolver

    两个标准配置

    Namespaces勾选上mvc

    <!-- 两个标准配置 -->
    	<!-- 将SpringMVC不能处理的请求交给tomcat -->
    	<mvc:default-servlet-handler/>
    	<mvc:annotation-driven>
    	<!-- 能支持SpringMVC更高级的一些功能,JSR303的校验,快捷的ajax...映射动态请求 -->
    	</mvc:annotation-driven>
    

    作用看注释。
    详细分析看:SpringMVC处理静态文件源码分析

    END

  • 相关阅读:
    【css3】使用filter属性实现改变svg图标颜色
    Live CD
    Linux定时任务 crontab(-l -e)、at、batch
    linux图形界面 KDE、GNOME
    shell脚本3——调试
    shell脚本2——控制语句
    bash:双引号和单引号
    shell脚本1——变量 $、read、``
    SSH
    Linux关机、重启、退出
  • 原文地址:https://www.cnblogs.com/famine/p/9798750.html
Copyright © 2011-2022 走看看