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