controller配置

Posted alloevil

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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;
    }

 

以上是关于controller配置的主要内容,如果未能解决你的问题,请参考以下文章

JMeter:逻辑控制器_模块控制器(Module Controller)

VSCode自定义代码片段11——vue路由的配置

VSCode自定义代码片段11——vue路由的配置

VSCode自定义代码片段11——vue路由的配置

Nginx 跨域

jmeterInclude Controller控件&Test Fragment的使用