zoukankan      html  css  js  c++  java
  • @RequestParam和@PathVariable的区别

    一:@RequestParam

     @RequestParam是传递参数的.

    @RequestParam用于将请求参数区数据映射到功能处理方法的参数上。

    public Object Login(@RequestParam(value = "name",defaultValue = "lisi") String name, @RequestParam("password")String password)

    在URL中发送请求:http://localhost:8080/welcome?name=lisi&&password=1234

    defaultValue是默认值。现在是默认为"lisi"。如果请求的name=zhangsan。是以实际的请求为准的。
    二:@PathVariable

    @PathVariable绑定URI模板变量值

    @RequestMapping(value="/users/{userId}/topics/{topicId}")  
    public String test(   @PathVariable(value="userId") int userId,    @PathVariable(value="topicId") int topicId)  

    如请求的URL为“控制器URL/users/123/topics/456”,则自动将URL中模板变量{userId}和{topicId}绑定到通过@PathVariable注解的同名参数上,即入参后userId=123、topicId=456。代码在PathVariableTypeController中

    1):

    @RequestParam是自己写给URL的。作为参数。

    @PathVariable是从URL中取到的值。作为Controller中入参。

    2):

    @RequestParam 是从request里面拿取值,

    @PathVariable 是从一个URI模板里面来填充

  • 相关阅读:
    java序列化进阶
    jQuery学习一(选择器)
    java poi 操作Excel常用方法总结
    mybatis批量foreach的使用
    java中关于try、catch、finally的总结
    MyEclipse使用指南(精简版)
    单例模式
    抽象工厂模式
    java.io.Serializable
    java.lang.string
  • 原文地址:https://www.cnblogs.com/bulrush/p/8862891.html
Copyright © 2011-2022 走看看