SimpleUrlHandlerMapping

Exisi 2022-06-28 14:10:03
Categories: Tags:

示例

<bean id="simpleUrlHandlerMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">

    <property name="mappings">

        <props>

            <!-- /hello 路径的请求交给 id 为 helloController 的控制器处理-->

            <prop key="/hello">helloController</prop>

        </props>

 

<!-- 直接传入路径请求和控制器id-->

<value>

    /welcome.htm=welcomeController

       /*/welcome.htm=welcomeController

       /helloGuest.htm=helloGuestController

</value>

 

    </property>

</bean>

 <!-- 注册控制类对象 -->

<bean id="helloController" class="controller.HelloController"></bean>

 

 

public class HelloController implements Controller {

 

    public ModelAndView handleRequest(javax.servlet.http.HttpServletRequest httpServletRequest, 

    javax.servlet.http.HttpServletResponse httpServletResponse) throws Exception {

        ModelAndView mav = new ModelAndView("index.jsp");

        return mav;

    }

}