来源: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的使用的更多相关文章

  1. Spring MVC之@RequestParam @RequestBody @RequestHeader 等详解

    (转自:http://blog.csdn.net/walkerjong/article/details/7946109#) 引言: 接上一篇文章,对@RequestMapping进行地址映射讲解之后, ...

  2. @RequestParam @RequestBody @PathVariable 等参数绑定注解详解

    文章主要讲解request 数据到handler method 参数数据的绑定所用到的注解和什么情形下使用. 简介: handler method 参数绑定常用的注解,我们根据他们处理的Request ...

  3. 《转载》Spring MVC之@RequestParam @RequestBody @RequestHeader 等详解

    引言: 接上一篇文章,对@RequestMapping进行地址映射讲解之后,该篇主要讲解request 数据到handler method 参数数据的绑定所用到的注解和什么情形下使用: 简介: han ...

  4. 注解 @RequestParam,@RequestHeader,@CookieValue,Pojo,servlet原生API

    1.@RequestParam 我们的超链接:<a href="springMvc/testRequestParam">testRequestParam</a&g ...

  5. SpringMVC注解@RequestParam全面解析---打酱油的日子

    在SpringMVC后台控制层获取参数的方式主要有两种,一种是request.getParameter("name"),另外一种是用注解@RequestParam直接获取.这里主要 ...

  6. spring mvc@RequestParam根据参数名获取传入参数值

    在SpringMVC后台控制层获取参数的方式主要有两种,一种是request.getParameter("name"),另外一种是用注解@RequestParam直接获取.这里主要 ...

  7. Spring @RequestParam @RequestBody @PathVariable 等参数绑定注解详解

    背景 昨天一个人瞎倒腾spring boot,然后遇到了一点问题,所以把这个问题总结一下. 主要讲解request 数据到handler method 参数数据的绑定,所用到的注解和什么情形下使用. ...

  8. Springmvc中@RequestParam传值中文乱码解决方案

    首先jsp表单里面有一些参数要传到controller中,通过以下方法接收: @RequestMapping(value="/orderPaper") public ModelAn ...

  9. SpringMVC常用注解實例詳解1:@Controller,@RequestMapping,@RequestParam,@PathVariable

    我的開發環境 框架:        springmvc+spring+freemarker 開發工具: springsource-tool-suite-2.9.0 JDK版本: 1.6.0_29 to ...

  10. SpringMVC使用@PathVariable,@RequestBody,@ResponseBody,@RequestParam,@InitBinder

    @Pathvariable public ResponseEntity<String> ordersBack(           @PathVariable String reqKey, ...

随机推荐

  1. 性能跃升50%!解密自主研发的金融级分布式关系数据库OceanBase 2.0

    小蚂蚁说: 相信大家对蚂蚁金服自主研发的金融级分布式关系数据库OceanBase的故事不再陌生了.在刚刚过去的2018年天猫双11中,成交额2135亿再次创造了新纪录,而支撑今年双11的支付宝核心链路 ...

  2. ZJOI-2017 R1游记

    无实力非既得利益的$xrdog$作为一名外卡选手去参加ZJOI2017啦... Day 0: 颓?(细节待填坑..) Day 1: 上午我来到讲课现场发现讲课内容是:搜索专题  QwQ不太清醒的我一下 ...

  3. Django中ORM简介与单表数据操作

    一. ORM简介  概念:.ORM框架是用于实现面向对象编程语言种不同类型系统的数据之间的转换 构建模型的步骤:重点 (1).配置目标数据库信息,在seting.py中设置数据库信息 DATABASE ...

  4. Java——HashMap

    获取数组长度 数组.length 获取下标 HashMap HashMap 构造函数 // 默认构造函数. HashMap() // 指定“容量大小”的构造函数 HashMap(int capacit ...

  5. flutter安装与配置 v1.2.1版本

    1---- 上面是下载地址https://flutter.dev/docs/development/tools/sdk/archive#windows 2---- 下载后,解压安装到C盘 3--- 测 ...

  6. Android自定义权限

    一.自定义权限 自定义权限,一般是考虑到应用共享组件时的安全问题.我们知道在四大组件 AndroidManifest 中注册的时候,添加 exported = "true" 这一属 ...

  7. python获取子进程的返回值

    用subprocess popen 的communicate   比如,用gdalinfo命令查看一个tiff文件的信息 x = subprocess.Popen(["gdalinfo&qu ...

  8. JAVA基础知识总结:十一

    一.内部类 一个类中包含着另外一个类,里面的类被称为内部类,外面的称为外部类 1.成员内部类 和成员变量或者成员方法平级的内部类 语法: 访问权限修饰符 class 外部类类名{ //成员变量 //成 ...

  9. Unity --- MeshRenderer之网格合并

    创建如图所示的对象结构,parent为空对象,然后将下面的代码挂载到parent对象上运行即可. using UnityEngine; using System.Collections; public ...

  10. Unity --- sharedMaterial 、material

    sharedMaterial: 无论如何更新材质的属性,内存中只会存在一份. material: 每次更新材质属性的时候,内存中都会重新new一份material作用于它,直到 Application ...