首页 > 其他分享 >常用参数注解

常用参数注解

时间:2022-09-25 14:12:57浏览次数:52  
标签:userName map 常用 PathVariable Map sec 参数 注解 id

路径变量@PathVariable

①获取指定路径变量:

 @GetMapping("/car/{id}/owner/{userName}")
    public Map<String,Object> getCar(@PathVariable("id") int id,
                         @PathVariable("userName") String userName){
        Map<String,Object> map = new HashMap<>();
        map.put("id",id);
        map.put("userName",userName);

        return map;
    }

 请求:http://localhost:8080/car/1/owner/zhangsan

返回:{"id":"1","userName":"zhangsan"}

②获取所有路径变量:

//使用map提取所有的路径变量,map必须是String类型
    @GetMapping("/car/{id}/owner/{userName}/{age}")
    public Map<String,String> getCar(@PathVariable() Map<String,String> kv){

        return kv;
    }

请求:http://localhost:8080/car/2/owner/lisi/30

返回:{"id":"2","userName":"lisi","age":"30"}

 

获取请求头@RequestHeader

①获取指定请求头

@GetMapping("/car/{id}/owner/{userName}")
    public Map<String,Object> getCar(@PathVariable("id") int id,
                         @PathVariable("userName") String userName,
                                    @RequestHeader("User-Agent") String userAgent){
        Map<String,Object> map = new HashMap<>();
        map.put("id",id);
        map.put("userName",userName);
        map.put("userAgent",userAgent);
        return map;
    } 

 

 请求返回:

{"userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36","id":1,"userName":"zhangsan"}

 ②获取所有的请求头

@GetMapping("/car/{id}/owner/{userName}")
public Map<String,String> getCar(@PathVariable("id") int id,
                     @PathVariable("userName") String userName,
                                @RequestHeader Map<String,String> heads){

    return heads;
}
{"host":"localhost:8080","connection":"keep-alive","cache-control":"max-age=0","sec-ch-ua":"\"Google Chrome\";v=\"105\", \"Not)A;Brand\";v=\"8\", \"Chromium\";v=\"105\"","sec-ch-ua-mobile":"?0","sec-ch-ua-platform":"\"Windows\"","upgrade-insecure-requests":"1","user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36","accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9","sec-fetch-site":"none","sec-fetch-mode":"navigate","sec-fetch-user":"?1","sec-fetch-dest":"document","accept-encoding":"gzip, deflate, br","accept-language":"zh-CN,zh;q=0.9","cookie":"Idea-71259e56=b05a3fec-a744-4e6b-aeb2-f38a5c6b6dd0; Webstorm-142c3cad=9dee10a5-f1c0-4ed5-97c6-4b442beeb5b3"}

 

  

 

标签:userName,map,常用,PathVariable,Map,sec,参数,注解,id
From: https://www.cnblogs.com/ixtao/p/16727762.html

相关文章

  • Linux常用命令(用户组管理命令)
    用户组管理命令每个用户都有一个用户组,系统可以对一个用户组中的所有用户进行集中管理。不同Linux系统对用户组的规定有所不同,如Linux下的用户属于与它同名的用户组,这......
  • 讨论一下你在项目中常用的那些数组API
    我报名了GoldstoneProjectPhase1Challenge——瓜分100,000奖池,这是我的第3篇文章,点击查看活动详情大批它是业务中非常高频的API。它基本上在商业中很有用。这是必......
  • Linux常用基本命令(时间日期及用户管理类)
    时间日期类1)基本语法date [OPTION]...[+FORMAT]2)选项说明选项功能-d<时间字符串>显示指定的“时间字符串”表示的时间,而非当前时间-s<日期时间>设置......
  • 夯实基础之tcp重传内核参数
    第一次握手超时重传参数第一次握手client发送SYN包时,超时重传参数#重传次数默认值$cat/proc/sys/net/ipv4/tcp_syn_retries5#调整重传次数$echo2>/proc/sys/......
  • 学习记录8方法的重载、可变参数、递归
    方法的重载重载就是在一个类中,又想同的函数名称,但形参不同的函数即,一个类中有两个同名的方法,但这两个类的“返回值类型”、“形参类型”、“形参个数”不同,而在程序中......
  • 利用props封装带有参数及回调事件的组件
    实现效果: 封装的组件:<template><viewclass="page-container-titleNav"><viewclass="content"><viewclass="left"><......
  • forms组件参见错误参数
    Fieldrequired=True,是否允许为空widget=None,HTML插件label=None,用于生成Label标签或显示内容......
  • 注解-自定义注解-元注解和解析注解
    注解-自定义注解-元注解元注解:就是用于描述注解的注解@Target:描述注解能够作用的位置@Retention:苗猪注解被保留的阶段@Documented:描述注解是......
  • 011——常用API(String , ArrayList)
    常用API(String,ArrayList)API(ApplicationProgrammingInterface,应用程序编程接口)Java写好的程序(功能),咱们可以直接调用。Oracle也为Java提供的这些功能代码......
  • c#常用的文本操作
    1.从index截取到字符串结束:string.Substring(index) 2.从index截取length长度的字符串:string.Substring(index,length)3.查找字符串最先出现的index://如果......