• SpringMVC中HandlerMapping的三种配置方式


    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
    <!--文件名springmvc-servlet.xml中的“springmvc”与web.xml的<servlet-name>springmvc</servlet-name>中的“springmvc”对应  -->
    <beans>
    <!-- HanderMapping-有3种访问Controller的方式 -->
    
    <!--方式一  根据简单URL查找Controller-->
    <!--     <bean id="simpleUrlHandlerMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
            <property name="mappings">
                <props>
                    <prop key="/index">indexController</prop>
                </props>
            </property>
        </bean> 
        <bean id="indexController" class="controller.IndexController"></bean>
        -->
        
    <!--方式二 根据beanname找到对应Conntroller  -->
    <!-- <bean class="org.springframework.web.servlet.mvc.support.ControllerBeanNameHandlerMapping"></bean>  
         <bean name="/index" class="controller.IndexController"></bean> --> 
        
    <!--方式三  根据控制类的类名访问Controller,访问时类的类名需要小写(加不加.do均可)    http://192.168.100.47:8080/springmvc/indexController -->
        <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"></bean>
        <bean class="controller.IndexController"></bean>
        
    </beans>

    controller 

    package controller;
    
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import org.springframework.web.servlet.ModelAndView;
    import org.springframework.web.servlet.mvc.Controller;
    
    public class IndexController implements Controller {
        public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
            ModelAndView mav = new ModelAndView("index.jsp");
            mav.addObject("message", "Hello Spring MVC");
            return mav;
        }
    }
  • 相关阅读:
    EXTJS 基本使用
    EXTJS 常用控件的使用
    EXTJS 验证与表单提交
    EXTJS 常用方法
    禁用USB移动盘的方法
    常用sql 函数练习示例
    .Net 中的反射(反射特性) Part.3
    Delphi調用.NET的WebService
    c#写的串口通讯
    打印控制
  • 原文地址:https://www.cnblogs.com/thiaoqueen/p/7681607.html
Copyright © 2020-2023  润新知