zoukankan      html  css  js  c++  java
  • controller配置

    第一种 URL对应bean

    第二种 为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.sgcc.controller.HelloController"></bean>

    可使用通配符

    第三种 URL匹配bean

    <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"></bean>
        <!-- 请求为hello*.do都将被匹配 -->
        <bean id="helloController" class="com.sgcc.controller.HelloController"></bean>

    第四种 注解

    <context:component-scan base-package="com.sgcc.controller"></context:component-scan>

    controller代码中,要写对应的注解。

    @Controller
    public class HelloController {
        @RequestMapping("/hello")
        public ModelAndView hello(HttpServletRequest req,HttpServletResponse rep){
            ModelAndView mv = new ModelAndView();
            
            mv.addObject("msg", "hello Springmvc Annotation");
            
            mv.setViewName("hello");
            return mv;
        }
  • 相关阅读:
    网页Tab控件
    ivy在eclipse中的重新加载
    es删除文档或者删除索引
    es修改数据
    es中插入数据
    创建es索引-格式化和非格式化
    MySQL常用字符串函数
    python各种类型转换
    python 3.4读取输入参数
    python异常捕获异常堆栈输出
  • 原文地址:https://www.cnblogs.com/alloevil/p/6064053.html
Copyright © 2011-2022 走看看