zoukankan      html  css  js  c++  java
  • SpringMVC-02 HandlerMapping的常见种类及注解

    HandlerMapping的常见种类

    HandleMapping:处理映射器,可以理解为为请求的url查找对应的Controller类.

    BeanNameUrlHandlerMapping

    根据bean标签的名称找到对应的Controller类。

    SimpleUrlHandlerMapping

    根据bean的id查找对应的Controller类。

    ControllerClassNameHandlerMapping

    根据controller类的名字找到对应的Controller。

    使用注解替代配置

    引入指定jar

    **1.包扫描:扫描注解所在包
    2.开启注解标签:Annotation
    **

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans" 
         xmlns:mvc="http://www.springframework.org/schema/mvc"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xmlns:context="http://www.springframework.org/schema/context"
         xsi:schemaLocation="http://www.springframework.org/schema/beans 
            http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context.xsd
            http://www.springframework.org/schema/mvc
            http://www.springframework.org/schema/mvc/spring-mvc.xsd">
         <!-- 包扫描 -->
         <context:component-scan base-package="com.hw.lb.controller.annotation"></context:component-scan>
         <!-- 启动注解器 -->
         <mvc:annotation-driven/>    
         <!-- 配置视图解析器 -->
          <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
               <property name="prefix" value="/WEB-INF/view/"/>
               <property name="suffix" value=".jsp"/>
          </bean>
    </beans>
    

    3.创建Controller类(在类中添加Controller注解,可以创建多个方法)

    package com.hw.lb.controller.annotation;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    @Controller
    public class FirstAnnotation {
         @RequestMapping("/list.do")
         public String list() {
               System.out.println("查询所有");
               return "login";
         }
    }
    
    
  • 相关阅读:
    Tomcat安装(安装版)
    Selenium自动化测试(一)之环境搭建
    Windows快速启动应用高效搜索文件工具-Listary
    Python3之jsonpath使用和json转换
    Python3操作SQLite数据库
    初识面向对象
    忘记虚拟机中Linux的登录密码解决办法
    win10自带虚拟机的使用(Hyper-v)
    nigx下配置tp5.1路由
    PHP无限极菜单
  • 原文地址:https://www.cnblogs.com/DT-Demo/p/11455777.html
Copyright © 2011-2022 走看看