美文网首页
Spring MVC 请求参数获取

Spring MVC 请求参数获取

作者: 陈岳陵 | 来源:发表于2015-07-24 00:08 被阅读320次

GET

  1. 请求 默认的 Content-Type = "application/x-www-form-urlencoded"
    所以 当Spring 使用
    @RequestMapping(value = "/pets", method=RequestMethod.GET,consumes = "application/x-www-form-urlencoded")
    //进行注解时不会返回415 错误[UNSUPPORTED_MEDIA_TYPE]。

  2. 参数直接放在方法里
    @RequestMapping(value = "/pets", method =RequestMethod.GET,consumes = "application/x-www-form-urlencoded" )
    public void getPet(String id, Model model) {
    System.out.println(id);
    }
    //请求参数 localhost:8080/pets?id=1
    //打印结果 1

  3. 含有参数的对象放在方法里

    @RequestMapping(value = "/pets", method =RequestMethod.GET,consumes = "application/x-www-form-urlencoded" )                              
      public void getPet(PetForm dataForm, Model model) {       
             System.out.println(dataForm.getId());
      }
    //请求参数 localhost:8080/pets?id=1
    //打印结果 1
    

相关文章

网友评论

      本文标题:Spring MVC 请求参数获取

      本文链接:https://www.haomeiwen.com/subject/ntwpqttx.html