来源: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. _event_phase_team

    EventId 事件ID Phase 阶段ID,从1开始 TeamId 事件玩家分组,攻守(防守为1,进攻为2),自定义阵营(_faction表自定义阵营ID),公会(公会guid) Graveyar ...

  2. 【BZOJ】3142: [Hnoi2013]数列

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3142 12年也有一个组合数学...(这几年的画风啊.... 考虑直接去做:DP? DP+容 ...

  3. FreeCodeCamp---advanced Algorithm Scripting解法

    Exact Change 设计一个收银程序 checkCashRegister() ,其把购买价格(price)作为第一个参数 , 付款金额 (cash)作为第二个参数, 和收银机中零钱 (cid) ...

  4. python特殊成员函数

    1.__init__():构造函数 2.__del__():析构函数 3.print(__doc__):打印描述信息 4.print(Dog.__module__):类来自的模块 5.print(d1 ...

  5. Lambda语法篇

    函数式接口 函数式接口(functional interface 也叫功能性接口,其实是同一个东西).简单来说,函数式接口是只包含一个方法的接口. Lambda语法 包含三个部分 一个括号内用逗号分隔 ...

  6. Linux修改hostname时/etc/hosts、/etc/sysconfig/network ,hostname,三者的区别和联系

    [root@localhost /]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.l ...

  7. Java将byte[]和int的互相转换

    /** * 将整数转换为byte数组并指定长度 * @param a 整数 * @param length 指定长度 * @return */ public static byte[] intToBy ...

  8. C# 遍历文件夹筛选目标文件

    有近400G的数据,首先需要写程序把目标文件标准化名称(相当耗时,各种情形,间接说明在数据采集过程中标准化操作的重要性,这样会给后续处理带来很多不必要的麻烦和消耗) 网上找了个方法还不错,还有一种递归 ...

  9. HTML第八章总结

    Expanding your vocabulary 总述 在上一章节介绍了 CSS 的基础之后,这一章节更加具体地展开关于 CSS 的各种 rules 能够达成的效果.比如 字体:font-famil ...

  10. 【异常及源码分析】org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping

    一.异常出现的场景 1)异常出现的SQL @Select("SELECT\n" + " id,discount_type ,min_charge, ${cardFee} ...