zoukankan      html  css  js  c++  java
  • springmvc 开涛 注解式控制器

    版本 定义处理器类 处理器映射适配器 备注 支持的注解
    2.5前 controller      
    2.5 注解

    DefaultAnnotationHandlerMapping

    AnnotationMethodHandlerAdapter

    @Controller

    @RequestMapping

    @Controller

    @RequestMapping

    @RequestParam

    @ModelAndView

    @SessionAttributes

    @InitBinder

    3.0 ... ... ... @PathVariable

    @CookieValue

    @RequestHeader

    @RequestBody

    @ResponseBody

    @ResponseStatus

    @ExceptionHandler

    @PathVariable

    3.1 ...

    RequestMappingHandlerMapping

    RequestMappingHandlerAdapter

    ...  

    请求的映射分为四种:URL,方法,参数,头

    在处理器类上 可以加 @Controller @RequestMapping,后者主要用于窄化功能处理方法的映射

    开涛讲得开启注解的方式 跟 孔浩讲得不同呀,前者是引入两个bean,后者是引入<context><mvc>标签?

    前者只会去发现@Controller,@RequestMapping;后者会扫描所有带注解的bean
    

    ***-servlet.xml应该放在WEB-INF目录下,这样使用classpath:***-servlet.xml

    URL路径映射

    普通URL

    URL模板

    ant风格:http://blog.csdn.net/h396071018/article/details/8278389  ?不能为空,*(0或多个字符) **(0或多个目录)都可以。最长匹配优先

    正则表达式:{变量名:正则表达式}

    或 的关系:value={"/", "/test"};

    请求方法映射

    或 的关系:method={RequestMethod.POST, RequestMethod.GET};

    如果需要支持OPTIONS、TRACE,请添加DispatcherServlet在web.xml的初始化参数:dispatchOptionsRequest 和 dispatchTraceRequest 为true。

    请求参数映射

    @RequestMapping(params="create") 有create参数

    @RequestMapping(params!="create") 没有create参数

    @RequestMapping(params="create=sfp") create=sfp

    @RequestMapping(params="create!=sfp") create!=sfp

    且 的关系 @RequestMapping(params={"test1", "test2=create"})

    @RequestMapping("/user")或@RequestMapping(value="/user")  对路径进行映射
    @RequestMapping(params="user")  对参数进行映射
    @RequestParam(value="user") 对参数进行映射
     
    

    请求头映射

    @RequestMapping(header="Accept") 跟请求参数类似

    接下来看生产者,消费者请求限定

     

  • 相关阅读:
    Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, ...
    问题:ORA-28000: the account is locked 用户锁住了。
    oracle连接数据库报错:ORA-01034: ORACLE not available(Oracle 不存在),ORA-27101: shared memory realm does not exist
    数据抽取Sql语句
    在Eclipse中部署Maven多模块项目
    Struts 学习记录
    eclipse中git插件无法向远程仓库提交tag的问题
    goldGrid-VBA-EXCLE处理
    SqlBulkCopy效率低下原因分析
    各种奇葩小问题
  • 原文地址:https://www.cnblogs.com/wang-jing/p/4567214.html
Copyright © 2011-2022 走看看