@RequestParam的使用
来源:http://825635381.iteye.com/blog/2196911
@RequestParam:
一、 基本使用,获取提交的参数
后端代码:
@RequestMapping("testRequestParam")
public String filesUpload(@RequestParam String inputStr, HttpServletRequest request) {
System.out.println(inputStr); int inputInt = Integer.valueOf(request.getParameter("inputInt"));
System.out.println(inputInt); // ......省略
return "index";
}
二、各种异常情况处理
1、可以对传入参数指定参数名
@RequestParam String inputStr
// 下面的对传入参数指定为aa,如果前端不传aa参数名,会报错
@RequestParam(value="aa") String inputStr
2、可以通过required=false或者true来要求@RequestParam配置的前端参数是否一定要传
// required=false表示不传的话,会给参数赋值为null,required=true就是必须要有
@RequestMapping("testRequestParam")
public String filesUpload(@RequestParam(value="aa", required=true) String inputStr, HttpServletRequest request)
3、如果用@RequestMapping注解的参数是int基本类型,但是required=false,这时如果不传参数值会报错,因为不传值,会赋值为null给int,这个不可以
@RequestMapping("testRequestParam") public String filesUpload(@RequestParam(value="aa", required=true) String inputStr,@RequestParam(value="inputInt", required=false) int inputInt
,HttpServletRequest request) { // ......省略
return "index";
}
解决方法:
“Consider declaring it as object wrapper for the corresponding primitive type.”建议使用包装类型代替基本类型,如使用“Integer”代替“int”
@RequestParam的使用的更多相关文章
- Spring MVC之@RequestParam @RequestBody @RequestHeader 等详解
(转自:http://blog.csdn.net/walkerjong/article/details/7946109#) 引言: 接上一篇文章,对@RequestMapping进行地址映射讲解之后, ...
- @RequestParam @RequestBody @PathVariable 等参数绑定注解详解
文章主要讲解request 数据到handler method 参数数据的绑定所用到的注解和什么情形下使用. 简介: handler method 参数绑定常用的注解,我们根据他们处理的Request ...
- 《转载》Spring MVC之@RequestParam @RequestBody @RequestHeader 等详解
引言: 接上一篇文章,对@RequestMapping进行地址映射讲解之后,该篇主要讲解request 数据到handler method 参数数据的绑定所用到的注解和什么情形下使用: 简介: han ...
- 注解 @RequestParam,@RequestHeader,@CookieValue,Pojo,servlet原生API
1.@RequestParam 我们的超链接:<a href="springMvc/testRequestParam">testRequestParam</a&g ...
- SpringMVC注解@RequestParam全面解析---打酱油的日子
在SpringMVC后台控制层获取参数的方式主要有两种,一种是request.getParameter("name"),另外一种是用注解@RequestParam直接获取.这里主要 ...
- spring mvc@RequestParam根据参数名获取传入参数值
在SpringMVC后台控制层获取参数的方式主要有两种,一种是request.getParameter("name"),另外一种是用注解@RequestParam直接获取.这里主要 ...
- Spring @RequestParam @RequestBody @PathVariable 等参数绑定注解详解
背景 昨天一个人瞎倒腾spring boot,然后遇到了一点问题,所以把这个问题总结一下. 主要讲解request 数据到handler method 参数数据的绑定,所用到的注解和什么情形下使用. ...
- Springmvc中@RequestParam传值中文乱码解决方案
首先jsp表单里面有一些参数要传到controller中,通过以下方法接收: @RequestMapping(value="/orderPaper") public ModelAn ...
- SpringMVC常用注解實例詳解1:@Controller,@RequestMapping,@RequestParam,@PathVariable
我的開發環境 框架: springmvc+spring+freemarker 開發工具: springsource-tool-suite-2.9.0 JDK版本: 1.6.0_29 to ...
- SpringMVC使用@PathVariable,@RequestBody,@ResponseBody,@RequestParam,@InitBinder
@Pathvariable public ResponseEntity<String> ordersBack( @PathVariable String reqKey, ...
随机推荐
- BZOJ 3585 mex
题目已经没有了 思路: 莫队+分块 首先有一个结论:所有的答案都在0到n之间,用反正法就能证明,所以所有大于n的数都可以看成n 离线,对询问区间进行莫队,再对答案的范围0到n进行分块 复杂度(n+2* ...
- Java 访问RabbitMQ
一.概述 前面学过ActiveMQ.ActiveMQ主要是实现的JMS规范,而RabbitMQ就是AMQP的一个具体实现. RabbitMQ里面有几个概念:生产者.消费者.消息.交换器.路由键.队列. ...
- MyBatis-session-SqlSession
The SqlSession instance is the most powerful in MyBatis. It is where you'll find all of the methods ...
- 开发自己的R包(转)
R不必说,数据统计分析可视化的必备语言,R包开发的门槛比较低,所以现在随便一篇文章都会发表一个自己的R包,这样有好处(各种需求早有人帮你解决了)也有坏处(R包太多,混乱,新手上手较难).作为生信工程师 ...
- C#流(stream)
http://www.cnblogs.com/liuxinls/archive/2013/02/15/2912968.html 流用于对IO处理 在System.IO名称空间中有以下类 BinaryR ...
- LeetCode--155--最小栈(java版)
设计一个支持 push,pop,top 操作,并能在常数时间内检索到最小元素的栈. push(x) -- 将元素 x 推入栈中. pop() -- 删除栈顶的元素. top() -- 获取栈顶元素. ...
- POJ-3107 Godfather 求每个节点连接的联通块数量
dp[n][2],维护儿子的联通块数量和父亲的联通块数量. 第一遍dfs求儿子,第二遍dfs求爸爸. #include<iostream> #include<cstring> ...
- 数组<-->变量
/** * *数组与变量之间转换 **/ $name='jb51'; $email='jb51@jb51.net'; $info=compact('name','email'); print_r($i ...
- chmod 没有x权限怎么办
解决方法1: # /lib64/ld-linux-x86-64.so.2 /bin/chmod 755 /bin/chmod //linux动态命令库 解决方法2:方法2提到的两种方法形 ...
- MySQL事务(三)
一.事务(Innodb锁)的隔离级别概述 并发事务带来的问题: 更新丢失(lost update):当两个或多个事务选择同一行,然后基于最初选定的值更新该行时,由于每个事务都不知道其他事务的存在,就会 ...