@RequestMapping是一个用来处理请求地址映射的注解,可用于类或方法上。用于类上,表示类中的所有响应请求的方法都是以该地址作为父路径。

RequestMapping注解有六个属性,下面我们把她分成三类进行说明。

1、 value, method;

value:     指定请求的实际地址,指定的地址可以是URI Template 模式(后面将会说明);

method:  指定请求的method类型, GET、POST、PUT、DELETE等;

@Controller
@RequestMapping("/appointments")
public class AppointmentsController { private AppointmentBook appointmentBook; @Autowired
public AppointmentsController(AppointmentBook appointmentBook) {
this.appointmentBook = appointmentBook;
} @RequestMapping(method = RequestMethod.GET)
public Map<String, Appointment> get() {
return appointmentBook.getAppointmentsForToday();
} @RequestMapping(value="/{day}", method = RequestMethod.GET)
public Map<String, Appointment> getForDay(@PathVariable @DateTimeFormat(iso=ISO.DATE) Date day, Model model) {
return appointmentBook.getAppointmentsForDay(day);
} @RequestMapping(value="/new", method = RequestMethod.GET)
public AppointmentForm getNewForm() {
return new AppointmentForm();
} @RequestMapping(method = RequestMethod.POST)
public String add(@Valid AppointmentForm appointment, BindingResult result) {
if (result.hasErrors()) {
return "appointments/new";
}
appointmentBook.addAppointment(appointment);
return "redirect:/appointments";
}
}
@RequestMapping(value="/owners/{ownerId}", method=RequestMethod.GET)
public String findOwner(@PathVariable String ownerId, Model model) {
Owner owner = ownerService.findOwner(ownerId);
model.addAttribute("owner", owner);
return "displayOwner";
}
@RequestMapping("/spring-web/{symbolicName:[a-z-]+}-{version:\d\.\d\.\d}.{extension:\.[a-z]}")
public void handle(@PathVariable String version, @PathVariable String extension) {
// ...
}
}

@RequestMapping用法详解的更多相关文章

  1. @RequestMapping 用法详解之地址映射

    @RequestMapping 用法详解之地址映射 引言: 前段时间项目中用到了RESTful模式来开发程序,但是当用POST.PUT模式提交数据时,发现服务器端接受不到提交的数据(服务器端参数绑定没 ...

  2. SpringMVC @RequestMapping 用法详解之地址映射

    @RequestMapping 用法详解之地址映射 http://blog.csdn.net/walkerjong/article/details/7994326

  3. [转帖]@RequestMapping 用法详解之地址映射(转)

    @RequestMapping 用法详解之地址映射(转) https://www.cnblogs.com/qq78292959/p/3760560.html 从csdn 发现的文章 然后csdn指向c ...

  4. @RequestMapping 用法详解之地址映射(转)

    引言: 前段时间项目中用到了RESTful模式来开发程序,但是当用POST.PUT模式提交数据时,发现服务器端接受不到提交的数据(服务器端参数绑定没有加任何注解),查看了提交方式为applicatio ...

  5. 9:@RequestMapping 用法详解之地址映射

    引言: 前段时间项目中用到了RESTful模式来开发程序,但是当用POST.PUT模式提交数据时,发现服务器端接受不到提交的数据(服务器端参数绑定没有加任何注解),查看了提交方式为applicatio ...

  6. @RequestMapping 用法详解之地址映射(转)

    这段时间项目中用到了RESTful模式来开发程序,但是当用POST.PUT模式提交数据时,发现服务器端接受不到提交的数据(服务器端参数绑定没有加任何注解),查看了提交方式为application/js ...

  7. @RequestMapping 用法详解

    简介: @RequestMapping RequestMapping是一个用来处理请求地址映射的注解,可用于类或方法上.用于类上,表示类中的所有响应请求的方法都是以该地址作为父路径. RequestM ...

  8. C#中string.format用法详解

    C#中string.format用法详解 本文实例总结了C#中string.format用法.分享给大家供大家参考.具体分析如下: String.Format 方法的几种定义: String.Form ...

  9. linux管道命令grep命令参数及用法详解---附使用案例|grep

    功能说明:查找文件里符合条件的字符串. 语 法:grep [-abcEFGhHilLnqrsvVwxy][-A<显示列数>][-B<显示列数>][-C<显示列数>] ...

随机推荐

  1. JavaEE视频学习

    1.实现东西应先实现静态,即使用固定的数据,比如链接数据库应先实现指定数据库如mysql的链接,成功后再向动态链接修改.方法也要这样写,一步步推进,不能一下子写出动态方法,这样很容易出错.

  2. Vim找不到配色文件的解决方法

    Vim新出了8.0,又成功的勾起了我的好奇心. 重新从零开始配置,结果第一步设置配色主题就没过,好丢人-- 提示找不到evening.vim配色文件,于是上网查了一下,有说改环境变量的,又说改这个改那 ...

  3. POI2012

    现在才开始写 POI 是不是太弱了? -Rendezvous 怎么说呢,我发现我的代码好长啊-长啊-长啊-长长长长长长长长长长长长长长长长长长长长长长啊- 大概就是在一个内向树上搞一个类似 lca 的 ...

  4. Zookeeper

    Zookeeper有个客户端,可以上传文件数据.然后Zookeeper有一个数据结构.像一种树.Zookeeper的主要作用有:维护配置文件(实时更新),选举leader(选举机制),感知节点(数据结 ...

  5. JAVA课程体系

    文件流 单点登录 maven.maven私服 jenkins 小程序 支付 webservice/webapi redis 工作流 权限:shiro 高并发 springBoot dubbo 消息推送 ...

  6. 发布 Ionic iOS 企业级应用

    转自:http://www.jianshu.com/p/c12fae498975 Ionic 项目开发完成之后呢,自然就是打包发布了,今天说说 iOS 的打包和发布.iOS 的发布方式分为三种:iOS ...

  7. Visual Studio Team System 2008 Team Suite(90 天试用版)

    安装完成后,在“控制面板”中启动“添加删除程序”,选中Vs2008,点击“更改.删除”,输入序列号:PYHYP-WXB3B-B2CCM-V9DX9-VDY8T

  8. ajax-服务器响应

    如果需要获得了来自服务器的响应,则使用XMLHttpRequest 对象的 responseText 或 responseXML 属性 responseText: 获得字符串形式的响应数据,当read ...

  9. 使用Visual Studio调试用户模式进程(Debugging a User-Mode Process Using Visual Studio)

    由于本人能力有限,翻译不足之处敬请谅解,欢迎批评指正:sunylat@163.com Visual Studio版本:Visual Studio 2015企业版,中文环境. MSDN原文:https: ...

  10. SQL时间相关

    SQL --本周第一天 SELECT DATEADD(Day,-(DATEPART(Weekday,getdate())+@@DATEFIRST-)%,getdate()) --or ,getdate ...