标签:and lan org view 汇总 请求 web scan rom
1.通过Url对应Bean
<bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"></bean> <bean name="/hello.do" class="com.test.controller.HelloController"></bean>
以上配置,访问/hello.do就会寻找ID为/hello.do的bean,此类方式仅适用于小型的应用系统。
2.为URL分配bean
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="mappings"> <props> <!-- key 对应url请求名 value对应处理器的id --> <prop key="/hello.do">helloController</prop> </props> </property> </bean> <bean id="helloController" class="com.test.controller.HelloController"></bean>
此类配置还可以使用通配符,访问/hello.do时,spring会把请求分配给helloController进行处理。
3.URL匹配bean
<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"></bean> <!-- 请求为hello*.do都将被匹配 --> <bean id="helloController" class="com.test.controller.HelloController"></bean>
4.注解
<!-- 扫描该包下的注解 --> <context:component-scan base-package="com.springmvcanno"/>
Controller代码中,要写对应的注解
@Controller public class HelloController { @RequestMapping("/hello") public ModelAndView hello(HttpServletRequest req, HttpServletResponse resp){ ModelAndView mav = new ModelAndView(); //封装要显示到视图中的数据 mav.addObject("msg", "hello springmvc"); //视图名 mav.setViewName("hello"); return mav; } }
标签:and lan org view 汇总 请求 web scan rom
原文地址:http://www.cnblogs.com/realvie/p/6354423.html