springMVC请求参数绑定
2015-07-26 11:28
302 查看
从客户端请求key/value数据,经过参数绑定,将key/value数据绑定到controller方法的形参上。
springmvc中,接收页面提交的数据是通过方法形参来接收。而不是在controller类定义成员变更接收!!!!
1
通过request对象获取请求信息
3
通过session对象得到session中存放的对象
作用:将model数据填充到request域。
如果不使用@RequestParam,要求request传入参数名称和controller方法的形参名称一致,方可绑定成功。
如果使用@RequestParam,不用限制request传入参数名称和controller方法的形参名称一致。
请求路径:http://localhost:8080/hello?pin=9,在接收参数中使用注解@requestparam(value="pin") int pins
在代码中就可以使用pins而不是pin
springmvc中,接收页面提交的数据是通过方法形参来接收。而不是在controller类定义成员变更接收!!!!
1.1 默认支持的类型
直接在controller方法形参上定义下边类型的对象,就可以使用这些对象。在参数绑定过程中,如果遇到下边类型直接进行绑定。1
HttpServletRequest
通过request对象获取请求信息2 HttpServletResponse
通过response处理响应信息3
HttpSession
通过session对象得到session中存放的对象4Model/ModelMap
model是一个接口,modelMap是一个接口实现。作用:将model数据填充到request域。
1.2 简单类型
通过@RequestParam对简单类型的参数进行绑定。如果不使用@RequestParam,要求request传入参数名称和controller方法的形参名称一致,方可绑定成功。
如果使用@RequestParam,不用限制request传入参数名称和controller方法的形参名称一致。
@RequestMapping(value = "/hello",method = {RequestMethod.GET,RequestMethod.POST}) public String getInfos(int pin){ // order.ListOrder(); System.out.println("from client inpyt"+pin); return "a"; }
请求路径:http://localhost:8080/hello?pin=9,在接收参数中使用注解@requestparam(value="pin") int pins
在代码中就可以使用pins而不是pin
@RequestMapping(value = "/hello",method = {RequestMethod.GET,RequestMethod.POST}) public String getInfos(@RequestParam("pin") int pins){ // order.ListOrder(); System.out.println("from client inpyt"+pins); return "a"; }
相关文章推荐
- 如何添加在eclipse 中添加 window Builder
- C#和Java的比较
- java中的关键字super
- Spring(十二)使用Spring的xml文件配置方式实现AOP
- java笔记--类与继承
- 开源 自由 java CMS - FreeCMS1.9 积分规则管理
- 编写spring配置文件时,不能出现帮助信息
- java里为什么主函数前面要加static修饰 2015-07-26 11:10 3人阅读 评论(0) 收藏
- JavaWeb学习笔记:第一个 WEB 应用程序
- 关于javaWeb里转发与重定向斜杠的问题
- Eclipse使用总结
- JAVA I/O 体系
- springMVC的转发和重定向及Controller参数
- 金额转大写及日期转大写(java)
- 【Java并发编程实战】-----线程基本概念
- mac eclipse实用快捷键总结
- struts2和struts1认识
- 【java并发编程实战】-----线程基本概念
- eclipse背景调成护眼色
- java List 排序 Collections.sort() 对 List 中的对象排序