通过RequestMapping注解可以定义不同的处理器映射规则。

1.1 URL路径映射

  @RequestMapping(value="/item")或@RequestMapping("/item")。

  value的秩是数组,可以将多个url映射到同一个方法。

1.2 窄化请求映射

  在class上添加@RequestMapping(url)指定通用请求前缀,限制此类下的所有方法请求url必须以请求前缀开头,通过此方法对url进行分类管理。 

  如下:

  @RequestMapping放在类名上边,设置请求前缀

    @Controller

    @RequestMapping("/item")

  方法名上边设置请求映射url:

    @RequestMapping放在方法名上边,如下:

      @RequestMapping("/queryItem ")

  访问地址为:/item/queryItem

1.3 请求方法限定

  • 限定GET方法

    @RequestMapping(method = RequestMethod.GET)

    如果通过Post访问则报错:

      HTTP Status 405 - Request method 'POST' not supported

    例如:

    @RequestMapping(value="/editItem",method=RequestMethod.GET)

  • 限定POST方法

    @RequestMapping(method = RequestMethod.POST)

    如果通过Post访问则报错:

      HTTP Status 405 - Request method 'GET' not supported

  • GET和POST都可以

    @RequestMapping(method={RequestMethod.GET,RequestMethod.POST})

最新文章

  1. NOPI Excel插件导入导出 图片批注
  2. Eclipse添加代码注释模板
  3. 自己写ORM框架 SqlHelper_DG C#(java的写在链接里)
  4. LeetCode - 31. Next Permutation
  5. HTML 编辑基础
  6. Git笔记 整理2
  7. Ext JS treegrid 发生的在tree上增加itemclick 与在其它列上增加actioncolumn 发生事件冲突(event conflict)的解决办法
  8. cogs 1008 贪婪大陆
  9. 第18天 ajax技术和javascript加强(json)
  10. Chapter 15_4 子模块和包
  11. NCE损失(Noise-Constrastive Estimation Loss)
  12. 在Linq to sql 和 Entity framework 中使用lambda表达式实现left join
  13. Markdown编辑器使用说明
  14. 计算概论(A)/基础编程练习2(8题)/5:点和正方形的关系
  15. 7.27-8.10 Problems
  16. CMake命令
  17. Windows10系统.NET Framework 3.5离线安装方法
  18. [转载]生活在 Emacs 中
  19. pthread_once函数的简单示例
  20. 【Foreign】Melancholy [线段树]

热门文章

  1. nodejs基础: 如何升级Noejs版本
  2. 长沙雅礼中学集训-------------------day2
  3. win7计算机右键属性打不开窗口的解决方法
  4. sqoop2的使用测试
  5. Celery ---- 分布式队列神器 ---- 入门
  6. vs2015 调试IIS
  7. 使用SendMessage进行进程间通信
  8. ABAP-索引
  9. LESS CSS 实例
  10. Python library not found: libpython2.7mu.so.1.0