Spring mvc中@RequestMapping 6个基本用法整理
继续整理,这个是前段时间用jsp开发的一个站点,说起来php程序员去做jsp程序确实有些小不适应,但是弄完后绝对对于这种强类型语言而比收获还是颇多的。
1,最基本的,方法级别上应用
@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 6个基本用法整理的更多相关文章
- 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 基本用法
@RequestMapping(value="/departments") public String simplePattern(){ System.out.println(&q ...
- Spring MVC中@RequestParam/@RequestBody/@RequestHeader的用法收集(转)
简介: handler method参数绑定常用的注解,我们根据他们处理的Request的不同内容部分分为四类:(主要讲解常用类型) A.处理requet uri部分(这里指uri template中 ...
- Spring MVC中的ModelMap作用及用法
ModelMap的作用: ModelMap对象主要用于传递控制方法传递数据到结果页面.类似于request的setAttribute方法的作用. 所以我们要想在jsp页面获取数据,只要将数据放到Mod ...
- Spring MVC中各个filter的用法
转载:http://blog.csdn.net/qyp1314/article/details/42023725 Spring MVC中各个filter的用法 2014-12-19 09:08 105 ...
随机推荐
- BestCoder Round #36 (hdu5199)Gunner(水题)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Gunner Time Limit: 8000/4000 MS (Java/Oth ...
- Gora官方文档之二:Gora对Map-Reduce的支持
参考官方文档:http://gora.apache.org/current/tutorial.html 项目代码见:https://code.csdn.net/jediael_lu/mygoradem ...
- HTML5画布(矩形)
canvas元素用于绘制图形. canvas元素是HTML5中新增的一个重要元素,元素本身是没有绘图能力,所有的绘制工作必须在javascript内部完成. 案例1: <!DOCTYPE htm ...
- 为Mac自带的Apache配置PHP和虚拟机
操作系统:os x 10.11.2 1.启动apache 打开终端(terminal),输入命令:sudo apachectl -k start ; 在浏览器地址栏中输入:http://localho ...
- lnmp 60秒的服务器缓存时间
1.问题 php代码写好之后执行发现居然没有生效,打断点,改代码.刷新都没有达到预期的效果.但是间隔60秒之后刷新就看到效果了,或者删除文件就里面见效. 2.原因 从phpinfo()页面输出搜索&q ...
- Json序列化与反序列化完整实例
前台代码: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1 ...
- tableViewCell 的删除按钮
- (UITableViewCellEditingStyle)tableView:(UITableView*)tableView editingStyleForRowAtIndexPath:(NSIn ...
- CI练手下,找找感觉
从军哥谈CI框架上看了点点. controller: <?php class Jayjun extends CI_Controller { public function __construct ...
- IC封装形式COF介绍
其实这个真不太懂,没有太多接触也没有比较好的资料,只能简单的了解一下了. 什么是卷带式覆晶薄膜封装 COF(Chip on film) COF是一种 IC 封装技术,是运用软性基板电路(flexibl ...
- ADO.Net对Oracle数据库的操作【转载】
一 ADO.Net简介 访问数据库的技术有许多,常见的有一下几种:开放数据库互联(ODBC).数据访问对象(DAO).远程数据对象 (RDO). ActiveX数据对象(ADO).我们今天主要要学习A ...