zoukankan      html  css  js  c++  java
  • SSM-SpringMVC-07:SpringMVC中处理器映射器

     

     ------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥-------------

    BeanNameUrlHandlerMapping和SimpleUrlHandlerMapping

    BeanNameUrlHandlerMapping属于springmvc默认的处理器映射器,配不配这个都可以

    因为它在springmvc的配置文件已经配置过了

    自己也可以再配置一下BeanNameUrlHandlerMapping,不过没什么用,在自己的xml配置文件中:

        <!--处理器映射器,写不写都行,这个默认值就这个-->
        <bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"></bean>

    SimpleUrlHandlerMapping处理器映射器配置:

    自己的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"
           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">
    
        <!--配置bean处理器-->
        <bean id="second" class="cn.dawn.day03simpleUrlHandlerMapping.FirstController"></bean>
        <!--视图解析器-->
        <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="prefix" value="/"></property>
            <property name="suffix" value=".jsp"></property>
        </bean>
    
        <!--处理器映射器-->
        <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
            <!--第一种方式-->
            <!--<property name="urlMap">
                <map>
                    <entry key="/hello">
                        <value>second</value>
                    </entry>
                </map>
            </property>-->
            <!--第二种方式-->
    
            <property name="mappings">
                <props>
                    <!--value值为上面那个映射器的id-->
                    <prop key="/hello">second</prop>
                </props>
            </property>
        </bean>
    
    </beans>

    然后我可以通过/hello来访问second那个处理器

  • 相关阅读:
    python 变量作用域
    python 函数与模块
    python 程序控制结构
    python zip() map() filter()
    python 迭代和列表解析
    python 字典视图
    Matlab程序设计
    Matlab 基本绘图练习 包含极坐标
    Matlab 软件绘图
    Pandas 控制输出格式和精度
  • 原文地址:https://www.cnblogs.com/DawnCHENXI/p/8624255.html
Copyright © 2011-2022 走看看