SpringMVC框架——常用注解
- @RequestMapping
Spring MVC 通过 @RequestMapping 注解将请求与业务方法进行映射,在方法定义处,在类定义都可以添加该注解。
常用参数:
1、value:指定请求的实际地址,@RequestMapping的默认值;
2、method:指定请求的类型,GET、POST、PUT、DELETE等;
3、params:指定请求必须包含的参数;
- @RequestMapping
参数绑定:
1、在业务方法定义时声明参数列表;
2、给参数添加@RequestParam注解;
传统风格 http://localhost:7777/hello/index?id=10&name=a
@RequestMapping(value = "/index",method = RequestMethod.GET,params = {"id=10","name"})
public String index(@RequestParam("id") int num,@RequestParam("name") String gender){
System.out.println(num);
System.out.println(gender);
return "index";
}
params = {"id=10","name"} 指定参数值,参数id必须传10; @RequestParam("id") int num,@RequestParam("name") String gender 传递的参数名与接收参数名不同时,使用@RequestParam绑定;
- @PathVariable
RESTful风格 http://localhost:7777/hello/rest/10/a
@RequestMapping("/rest/{id}/{name}")
public String rest(@PathVariable("id") int id,@PathVariable("name") String name){
System.out.println("rest");
System.out.println(id);
System.out.println(name);
return "index";
}
使用@PathVariable("id") int id, @PathVariable("name") String name绑定参数
- @CookieValue
映射Cookie
@RequestMapping("/cookie")
public String cookie(@CookieValue("JSESSIONID") String sessionId){
System.out.println(sessionId);
return "index";
}
OK.
SpringMVC框架——常用注解的更多相关文章
- (三)SpringMVC之常用注解
SpringMVC的常用注解 注解 说明 @Controller 用于说明这个类是一个控制器 @RequestMapping 用于注释一个控制器类或者控制器类的方法 @RequestParam 用于将 ...
- SpringMVC的常用注解
在SpringMVC中常用的注解主要都是用于Controller上,所以下面的四大不同类型的注解都是根据它们处理的request的不同内容部分来区分的: 处理requ ...
- springMvc之常用注解介绍
@requestbody和@requestparam的用法 获取请求参数的方法 get请求: 直接获取request 如: public String getHtml(HttpServletR ...
- SpringMVC相关常用注解
@Controller: @Controller 用于标记在一个类上,使用它标记的类就是一个SpringMVC Controller 对象 @RequestMapping: RequestMappin ...
- Spring和SpringMVC的常用注解
Spring的部分: 使用注解之前要开启自动扫描功能 其中base-package为需要扫描的包(含子包). <context:component-scan base-package=" ...
- SpringMVC框架使用注解执行定时任务(转)
首先要配置我们的SpringMVC文件 xmlns 加下面的内容: xmlns:task="http://www.springframework.org/schema/task" ...
- springMVC的常用注解有哪些?
1.@Controller @Controller 用于标记在一个类上,使用它标记的类就是一个SpringMVC Controller 对象.分发处理器将会扫描使用了该注解的类的方法,并检测该方法是否 ...
- springmvc:常用注解
一.RequestParam注解 作用: 把请求中指定名称的参数给控制器中的形参赋值. 属性: value:请求参数中的名称. required:请求参数中是否必须提供此参数.默认值:true.表示必 ...
- 教你搭建SpringMVC框架( 更新中、附源码)
一.项目目录结构 二.SpringMVC需要使用的jar包 commons-logging-1.2.jar junit-4.10.jar log4j-api-2.0.2.jar log4j-core- ...
随机推荐
- [洛谷P3391] 文艺平衡树 (Splay模板)
初识splay 学splay有一段时间了,一直没写...... 本题是splay模板题,维护一个1~n的序列,支持区间翻转(比如1 2 3 4 5 6变成1 2 3 6 5 4),最后输出结果序列. ...
- GLSL 的各种着色器效果
Site Defunct 注意!截止到 16/9/2019 ,这个博客已经被搬迁到了 这里 .以后我的东西都会发在那里.拜拜啦! GLSL 很牛逼 Vignette ScanLine Pixelate ...
- Python 搭建webdriver环境遇到的问题总结
安装过程是参考<selenium2Python自动化测试实战>中Pythonwebdriver环境搭建章节 在安装过程中,遇到了一些问题,总结一下,为日后自己再遇到相同问题做个笔记以便查看 ...
- python编程基础之集合
集合是是基本数据类型的一种集合类型. 作用:去重 属性:intersection.union.difference.issubset 实例: list_1=[1,2,3,4,3,5,2,6,1]lis ...
- 录音文件lame转换MP3相关配置
文件下载整个功能完成了,那么对应的文件上传也跑不了.So~ Look here~ 业务需求是录制音频然后上传到七牛并且Android可以读. 与安卓沟通了一下统一了mp3格式,大小质量都不错.由于AV ...
- CentOS7搭建FTP Server
本文主要记录CentOS下FTP Server的安装和配置流程. 安装vsftpd yum install -y vsftpd 启动vsftpd service vsftpd start 运行下面的命 ...
- C++银行储蓄程序代码
*/ * Copyright (c) 2016,烟台大学计算机与控制工程学院 * All rights reserved. * 文件名:text.cpp * 作者:常轩 * 微信公众号:Worldhe ...
- 下载cv2时下载失败或下载成功却无法使用怎么办
最近我也在安装cv2的时候遇到了奇怪的问题,导致在安装cv2的时候无法使用.我在网上查了各种资料,虽然都对的,但都不太全面.本文就把安装cv2时可能遇到的各种奇怪的问题的解决方案做一个总结,供大家参考 ...
- 端口占用的一种形式 Failed to initialize end point associated with ProtocolHandler ["ajp-bio-8090"] java.net.BindException: Address already in use: JVM_Bind <null>:8090
严重: Failed to initialize end point associated with ProtocolHandler ["ajp-bio-8090"]java.ne ...
- 用table类型布局一个新闻网页
<html><head><meta http-equiv="Content-Type" content="text/html; charse ...