springMVC请求参数绑定

来源:互联网 发布:没离开过高音数据 编辑:程序博客网 时间:2024/05/01 19:22

从客户端请求key/value数据,经过参数绑定,将key/value数据绑定到controller方法的形参上。

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";    }


 

 

0 0