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- ...
随机推荐
- springboot 不同类型多数据源配置及使用
springboot多数据源配置: datasource.master.jdbc=jdbc:mysql://localhost:3306/test?useUnicode=true&charac ...
- stat()函数--------------获取文件信息
stat():用于获取文件的状态信息,使用时需要包含<sys/stat.h>头文件. 函数原型:int stat(const char *path, struct stat *buf): ...
- RxJava学习笔记(操作符)
前言 上一篇文章介绍了RxJava的基础知识和简单实现,篇幅已经比较多了,所以把操作符(Operators)相关的内容放在这一篇.有了上一篇文章的基础,相信会比较容易理解操作符相关的内容了. 操作符( ...
- react-router简单使用方法
使用 传值 非Link跳转 路由返回 v2,v3里的跳转,返回和传值 问题 react-router版本 v4.x 跟着官网 https://reacttraining.com/react-route ...
- cordova+jquery form上传里面的一些诡异坑
在浏览器里面执行很正常的代码,打包到手机上测试就出问题了,浏览器中的执行版本如下: <!DOCTYPE html> <html lang="en"> < ...
- Redis(1)——5种基本数据结构
一.Redis 简介 "Redis is an open source (BSD licensed), in-memory data structure store, used as a d ...
- SpringBoot快速上手系列01:入门
1.环境准备 1.1.Maven安装配置 Maven项目对象模型(POM),可以通过一小段描述信息来管理项目的构建,报告和文档的项目管理工具软件. 下载Maven可执行文件 cd /usr/local ...
- VUE中登录密码显示与隐藏的最简设计——基于iview
目录 VUE中登录密码显示与隐藏的最简设计--基于iview 1.背景 2.实现最终效果 2.1 隐藏密码 2.2 显示密码 3.实现思路 3.1 v-if判断当前密码显示状态 3.2 密码隐藏状态 ...
- SpringBoot 全局异常处理 @RestControllerAdvice +@ExceptionHandler 请求参数校验
ControllerAdvice 指示带注释的类辅助“控制器”. 作为的特殊化@Component,允许通过类路径扫描自动检测实现类. 通常用于定义@ExceptionHandler, @InitBi ...
- Linux进程操作记录
关于Gunicorn如何终止进程: 1.用进程树显示主进程PID: pstree -ap | grep gunicorn 2.如果有daemon进程无法用kill -9删除(可能是因为daemon屏蔽 ...