Spring mvc中@RequestMapping 基本用法
- @RequestMapping(value="/departments")
- public String simplePattern(){
- System.out.println("simplePattern method was called");
- return "someResult";
- }
则访问http://localhost/xxxx/departments的时候,会调用 simplePattern方法了
2) 参数绑定
- @RequestMapping(value="/departments")
- public String findDepatment(
- @RequestParam("departmentId") String departmentId){
- System.out.println("Find department with ID: " + departmentId);
- return "someResult";
- }
形如这样的访问形式:
/departments?departmentId=23就可以触发访问findDepatment方法了
3 REST风格的参数
- @RequestMapping(value="/departments/{departmentId}")
- public String findDepatment(@PathVariable String departmentId){
- System.out.println("Find department with ID: " + departmentId);
- return "someResult";
- }
形如REST风格的地址访问,比如:
/departments/23,其中用(@PathVariable接收rest风格的参数
4 REST风格的参数绑定形式之2
先看例子,这个有点象之前的:
- @RequestMapping(value="/departments/{departmentId}")
- public String findDepatmentAlternative(
- @PathVariable("departmentId") String someDepartmentId){
- System.out.println("Find department with ID: " + someDepartmentId);
- return "someResult";
- }
这个有点不同,就是接收形如/departments/23的URL访问,把23作为传入的departmetnId,,但是在实际的方法findDepatmentAlternative中,使用
@PathVariable("departmentId") String someDepartmentId,将其绑定为
someDepartmentId,所以这里someDepartmentId为23
5 url中同时绑定多个id
- @RequestMapping(value="/departments/{departmentId}/employees/{employeeId}")
- public String findEmployee(
- @PathVariable String departmentId,
- @PathVariable String employeeId){
- System.out.println("Find employee with ID: " + employeeId +
- " from department: " + departmentId);
- return "someResult";
- }
这个其实也比较好理解了。
6 支持正则表达式
- @RequestMapping(value="/{textualPart:[a-z-]+}.{numericPart:[\\d]+}")
- public String regularExpression(
- @PathVariable String textualPart,
- @PathVariable String numericPart){
- System.out.println("Textual part: " + textualPart +
- ", numeric part: " + numericPart);
- return "someResult";
- }
比如如下的URL:/sometext.123,则输出:
Textual part: sometext, numeric part: 123.
Spring mvc中@RequestMapping 基本用法的更多相关文章
- Spring mvc中@RequestMapping 6个基本用法
Spring mvc中@RequestMapping 6个基本用法 spring mvc中的@RequestMapping的用法. 1)最基本的,方法级别上应用,例如: Java代码 @Reques ...
- Spring mvc中@RequestMapping 6个基本用法小结
Spring mvc中@RequestMapping 6个基本用法小结 小结下spring mvc中的@RequestMapping的用法. 1)最基本的,方法级别上应用,例如: @RequestMa ...
- 转:Spring mvc中@RequestMapping 6个基本用法小结
Spring mvc中@RequestMapping 6个基本用法小结 发表于3年前(2013-02-17 19:58) 阅读(11698) | 评论(1) 13人收藏此文章, 我要收藏 赞3 4 ...
- Spring mvc中@RequestMapping 6个基本用法小结(转载)
小结下spring mvc中的@RequestMapping的用法. 1)最基本的,方法级别上应用,例如: @RequestMapping(value="/departments" ...
- Spring MVC中@RequestMapping注解使用技巧(转)
@RequestMapping是Spring Web应用程序中最常被用到的注解之一.这个注解会将HTTP请求映射到MVC和REST控制器的处理方法上. 在这篇文章中,你将会看到@RequestMapp ...
- Spring mvc中@RequestMapping 6个基本用法整理
继续整理,这个是前段时间用jsp开发的一个站点,说起来php程序员去做jsp程序确实有些小不适应,但是弄完后绝对对于这种强类型语言而比收获还是颇多的. 1,最基本的,方法级别上应用 @RequestM ...
- Spring MVC中各个filter的用法
转载:http://blog.csdn.net/qyp1314/article/details/42023725 Spring MVC中各个filter的用法 2014-12-19 09:08 105 ...
- Spring MVC 解读——@RequestMapping (1)(转)
转自:http://my.oschina.net/HeliosFly/blog/212329 Spring MVC 解读——@RequestMapping 为了降低文章篇幅,使得文章更目标化,简洁化, ...
- Http请求中Content-Type讲解以及在Spring MVC中的应用
引言: 在Http请求中,我们每天都在使用Content-type来指定不同格式的请求信息,但是却很少有人去全面了解content-type中允许的值有多少,这里将讲解Content-Type的可用值 ...
随机推荐
- Ubuntu 16.04 装机后如何永久更改ulimit和修改MySQL的存储路径datadir
Ubuntu 16.04 装机后的配置要点: 1. 网络的配置 2. 更改源列表 3. 永久更改ulimit ulimit限制着程序打开文件的数目,默认情况下为1024,作为服务器使用时,这个数字往往 ...
- 执行nvidia-smi出错
执行nvidia-smi出错 NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver. Make su ...
- D - Nested Segments CodeForces - 652D (离散化+树桩数组)
D - Nested Segments CodeForces - 652D You are given n segments on a line. There are no ends of some ...
- linux crontab 定时任务执行
cron机制 cron可以让系统在指定的时间,去执行某个指定的工作,我们可以使用crontab指令来管理cron机制 crontab参数 -u:这个参数可以让我们去编辑其他 ...
- VSCode远程连接Docker
一.Docker开启远程访问 [root@local host ~]# vi /lib/systemd/system/docker.service #修改ExecStart这行 ExecStart=/ ...
- (八)zabbix获取到的数值自定义单位
1) 查找php文件 # find / -name "func.inc.php" /usr/share/zabbix/include/func.inc.php 2)修改文件 #vi ...
- DevExpress Blazor组件全新来袭!增强Data Grid、TreeView API
点击获取DevExpress v19.1.7最新完整版试用下载 DevExpress UI for Blazor即将在最新的v19.1.8中可用,此次更新发布包括DevExpress Blazor组件 ...
- Pandas中DataFrame数据合并、连接(concat、merge、join)之concat
一.concat:沿着一条轴,将多个对象堆叠到一起 concat(objs, axis=0, join='outer', join_axes=None, ignore_index=False, key ...
- Linux - TCP/IP网络协议基础
1.0 Tcp / IP 背景介绍 上世纪70年代,随着计算机的发展,人们意识到如果想要发挥计算机的更大作用,就要讲世界各地的计算机连接起来. 但是简单的连接时不够的,因为计算机之间无法沟通.因此设计 ...
- jquery submit选择器 语法
jquery submit选择器 语法 作用::submit 选择器选取类型为 submit 的 <button> 和 <input> 元素.如果 <button> ...