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模板里面来填充

  • 相关阅读:
    vb代码控制 Excel锁定单元格
    SendMessage
    vb 中Treeview控件的一些问题!
    NGWS runtime C# 开始学习 第一天 (2006.6.7)
    DTS Transform Data Task的使用
    GetTickCount
    ASP.NET 2.0 中Login控件的使用
    core dump解析(2)
    tcp滑动窗口机制
    linux 查看文件夹大小 du命令
  • 原文地址:https://www.cnblogs.com/bulrush/p/8862891.html
Copyright © 2011-2022 走看看